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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory Scanning

Status
Not open for further replies.

ulchm

Programmer
May 22, 2007
23
CA
Hello,

I need to scan a folder and all subfolders looking for pdf and xls files grabbing each file name.

Not sure exactly how this can be accomplished. Is there anyone that can point me in the right direction.
 
Check into the DirectoryInfo Class

[sub]____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood[/sub]
 
You should check the help files: Here is a code snipped driectly from the VS help files:
Code:
        For Each foundFile As String In _
        My.Computer.FileSystem.GetFiles("C:\TestDir")
            Dim check As String = _
            System.IO.Path.GetFileName(foundFile)
            MsgBox("The file extension is " & check)
        Next
 
Sorry I should've been more specific, not looking for how to get the info, more the recursion side of it is what I can't get my head around.

I have a directory list, but then to go inside of each directory, checking for more directories, then inside of each of those etc.

That's what I'm having a hard time getting my head around for the time being.
 
Sounds like you're more stuck in a scripting world.

Did you check the class I pointed you to? If you read into and check the methods that are available to you you might just see one called DirectoryInfo.GetDirectories Method and the Directory.GetDirectories Method

[sub]____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood[/sub]
 
I have done this by creating a Function that can call its self:

1) Call the function to check a path you give, 'ScanFolder("c:\MyFolder")'
2) The function scans the files for the extensions and saves them in an array
3) The function then loops through each folder under the path and calls its self (goto step 1 with subfolder path, ScanFolder("c:\MyFolder\SubFolder")'...)

You may want to use Thread.Sleep(100) so that your application doesn't lock up whilst it scans very large and deep folders.

The array would then contain all of the paths\files that have the given extensions.

I would give you an example, but I use 2003 and as I can see from a prev post, the commands are different for 2005 folders.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top