finding all file in folder + subfolders
hi,
I want to find all the file in a folder + subfolder
need to have the full path + filename, is this possbile? is there a standard fucntion to do this?
thanks
[182 byte] By [
dublindude] at [2007-11-20 11:15:52]

# 1 Re: finding all file in folder + subfolders
Not as such a standard function there is one way to do it:
Option Explicit
Private FSO As New FileSystemObject
Private FileCount As Long
Private Sub ScanFolder(Fold As Folder)
Dim fi As File
Dim fo As Folder
For Each fi In Fold.Files
txtFiles.Text = txtFiles.Text + fi.Path + vbCrLf
FileCount = FileCount + 1
Next
For Each fo In Fold.SubFolders
ScanFolder fo
Next
End Sub
Private Sub btnStart_Click()
Dim fld As Folder
txtFiles.Text = ""
Set fld = FSO.GetFolder(txtPath.Text)
If Not fld Is Nothing Then ScanFolder fld
txtFiles.Text = txtFiles.Text + CStr(FileCount) + " files counted."
End Sub
You need a form, a multiline textbox to display the filenames, a textbox to enter the path to list and a button to start the scanning.
The example adds all filenames in txtPath to the textbox named txtFiles
The sub ScanFolder recursively calls itself to accomplish the scan of all subfolders.
This is not the fastest method, but it is most comprehensive to understand how you can do the search through all subfolders.
P.S.: You need a reference to 'Microsoft Scripting Runtime' within your project.
WoF at 2007-11-9 19:33:47 >

# 2 Re: finding all file in folder + subfolders
Using your source code above, how to retrieve all *.DLL in my local machine?
or
How to retrieve all *.DLL from other machine (viewing only) ?
thank you
rpc86 at 2007-11-9 19:34:39 >

# 3 Re: finding all file in folder + subfolders
Add this:
If Right$(fi.Path ,4)=".DLL" then ' Do something (or use <> for NOT)
# 4 Re: finding all file in folder + subfolders
Thanks.
What I want is, if I type on the TextBox as *.*, regarding of the folder name, the program must retrieve all files. If I type *.EXE all, Exe files will be loaded.
Another question is, I need to retrieve files from other computer (remote) using IP Address.
I tried this but it gave me Bad File Name or Number (Error Code 52).
Please Help.
rpc86 at 2007-11-9 19:36:42 >

# 5 Re: finding all file in folder + subfolders
The FSO should work with network paths as well.
\\Computername\Sharename
\\Computername\Sharename\Subfolder...
are both valid within the file system and should work.
\\Computername alone does not work. You need to specify the name of a shared folder which is available in the network.
For your specification you have to write a more complex if-statement like:
dim ft$, ftype$, p% 'need some more variables
'before loop extract filetype from input field
ftype$ = LCase(Mid$(TextBox.Text, InstrRev(TextBox.Text, ".")))
...
for each fi in Fold.Files
'we have to test if there is a '.' in the name
p = InstrRev(fi.Name, ".")
'now the matching
if p then ft$ = Lcase(Mid$(fi.Name, p)) else ft$=""
if ftype$ = ".*" or ftype$ = ft$ then ...
...
Also one might think of a different loop for the files, using the Dir statement.
WoF at 2007-11-9 19:37:45 >
