Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create directory folders from list of files

Status
Not open for further replies.

Delphiwhat

Programmer
Apr 1, 2003
74
EU
Hi folks

Can somene help me witha little piece of code.

I have a directory which contains a list of files. what i want to do is press a button and I will get a list of folders created. One folder is created per file and named the same as the file.

so if i had

C:\myfiles\file1001.txt
\file1002.txt
\file1003.txt
\file1004.txt

after pressing the button I would end up with

C:\myfiles\file1001\file1001.txt
\file1002\file1002.txt
\file1002\file1003.txt
\file1002\file1004.txt

If the directory already exists then the folder is not created

any ideas?

thanks

delphi
 
You will need to use a Windows API call to create the folders. (after you change your current directory, obtain the file list via dirlist or similar method, and extract the string for the folder name).

Here is a code snippet from Sybase...

CreateDirectoryA( )
This function create a new directory folder under the current directory.The second argument is exclusively used by NT and can be ignored under Win95. There is no PowerBuilder equivalent.

Global External Function:
FUNCTION boolean CreateDirectoryA(ref string pathname, int sa) LIBRARY "Kernel32.dll"

Script:
boolean rtn
string l_dir
l_dir = "API Demo"
rtn = CreateDirectoryA(l_dir, 0)
If rtn then
MessageBox("New Directory Created", "API Demo directory is located under current directory.")
else
MessageBox("CreateDirectory", "Failed")
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top