|
-
Nov 11th, 2008, 10:53 AM
#1
Thread Starter
PowerPoster
[RESOLVED] How to get a list of all files and folders in a drive
I am trying to write a program to output a list of all the files and folders in a drive, and I am wondering what methods people would use to achieve this so I can work out which one is fastest and best for my purposes.
My first attempt, of course, was with the dir() command and I wrote a simple yet effective method of recursive checking (I'm aware dir() doesn't work well with recursive checking, but it doesn't follow a new branch until it has finished in the current folder, and it builds up a list of new folder branches to check) but the problem with using dir() is attributes...if I set it to vbDirectory it lists vbDirectory AND files without any attributes. I am aware that there's a workaround for that where I can do a list of all the files without attributes then of vbDirectory then remove any that are in both lists, but this is a lot of extra work
The code I wrote for the dir() method:
Code:
Private Function getdrive(dr As String) As String
Do
drvinf = Dir(dr, vbDirectory)
Do
If drvinf <> "" Then
Debug.Print drvinf 'Used for testing
AddDir (dr & drvinf)
drvinf = Dir(, vbDirectory)
End If
Loop While drvinf <> ""
curdircheck = curdircheck + 1
dr = dirs(curdircheck)
Loop While curdircheck < dircount
End Function
Private Function AddDir(direc As String) As String
dircount = dircount + 1
dirs(dircount) = direc
End Function
As I said above, the problem there is vbDirectory doesn't list JUST the directories, it adds files without any attributes...any better suggestions or ideas for improvement?
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|