Jingya
asked on
How to create a file list to list all the, let's say *.txt files, in a driver?
I need to create a list of files to list all the files in a directory (or a driver). These files follow certain patterns (let's say *.frm, *.bas, ....) and may be in the subdirectories, or sus-subdirectories. Then I will process each file accordingly.
I would use a file list box with a .pattern property of '*.txt' etc. Now you can individually process each item in the list box.
qhenry
qhenry
Hi again,
Another method you could use would be to use the FindFirstFile and FindNextFile API calls; these allow you to retrieve extended information relating to the files too - including file size, date etc. etc.
Pete
Another method you could use would be to use the FindFirstFile and FindNextFile API calls; these allow you to retrieve extended information relating to the files too - including file size, date etc. etc.
Pete
ASKER
I appreciate the answers. But these answers are too simple and do not answer the key point -- the list should include all the qualified files in all the sub- and sub-sub- directories. This is the key point!! I want a smart way to do it. I don't think this question worths more than 50 point. All we need is to list the herach of subdirectories and then dir each directory. Principlely this is not difficult but tedious. I wonder whether we could do this in a smart way.
ASKER
Further comment: Let me make the question more clear. I want a code automatically search and find the sub- sub-sub- directory structure in an assigned directory or disk drive, then search each directory to find files ended with .txt and list the file name in a file name array for further processing.
So, just to quantify one more time - you want a method that will allow you to start searching, say, in the root directory and have the search performed over all sub-directories from that point.
Pete
Pete
ASKER
Pete:
Exactly as you discribed! Thank you to help me clarify the question.
Jingya
Exactly as you discribed! Thank you to help me clarify the question.
Jingya
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm not sure if you want the programme to automatically search down through the subdirectories or not. The following code will print all of the files ending .txt in the current directory to the screen, although you could modify the *.txt property to include a directory path as well....
'Declare local variables
Dim sFileName As String
'Get the first file that matches the file mask
sFileName = Dir$("*.txt")
'Loop util no more matches are found
Do While sFileName <> ""
'Display the filename
Me.Print sFileName
'Get the next file that matches the criteria
sFileName = Dir$
Loop
Hope this helps
Pete