Re: All Subdirectories

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



FYI, I ran into one very small glitch. I do not have access to one of the
subdirectories. Added this little tidbit of code... Seems to be running
again...

Function DoTheSubFolders(ByRef objFolders As Scripting.Folders, _
ByRef lngN As Long, ByRef strTitle As String)
Dim scrFolder As Scripting.Folder
Dim scrFile As Scripting.File
Dim lngCnt As Long

On Error Goto ErrorHandler
For Each scrFolder In objFolders
For Each scrFile In scrFolder.Files
If scrFile.Name Like strTitle Then
Cells(lngN, 2).Value = scrFile.Path
lngN = lngN + 1
End If
Next 'scrFile

'If there are more sub folders then go back and run function again.
If scrFolder.SubFolders.Count > 0 Then
DoTheSubFolders scrFolder.SubFolders, lngN, strTitle
End If
Next 'scrFolder

ErrorHandler:
Set scrFile = Nothing
Set scrFolder = Nothing
End Function

--
HTH...

Jim Thomlinson


"Jim Cone" wrote:

> Hi Jim,
> Why reinvent the wheel. This ought to work...
> Regards,
> Jim Cone
> San Francisco, USA
>
> Microsoft Windows Script 5.6 Documentation
> http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp
> '----------------------------------
> Option Explicit
> Option Compare Text
> Sub ListFoldersAndSubFolderAndFiles()
> Jim Cone - San Francisco, USA - May 24, 2005/July,02, 2005
> 'Requires a project reference to "Microsoft Scripting Runtime" (scrrun.dll)
> 'List all files and folders in the specified folder.
>
> Dim objFSO As Scripting.FileSystemObject
> Dim objFolder As Scripting.Folder
> Dim objFile As Scripting.File
> Dim strPath As String
> Dim strName As String
> Dim lngNum As Long
>
> 'Specify the folder...
> strPath = "C:\Documents and Settings"
> 'Specify the file to look for...
> strName = "*.xls"
> Set objFSO = New Scripting.FileSystemObject
> Set objFolder = objFSO.GetFolder(strPath)
> lngNum = 2
>
> For Each objFile In objFolder.Files
> If objFile.Name Like strName Then
> Cells(lngNum, 2) = objFile.Path
> lngNum = lngNum + 1
> End If
> Next 'objFile
> Set objFile = Nothing
>
> 'Call recursive function
> DoTheSubFolders objFolder.SubFolders, lngNum, strName
>
> Set objFSO = Nothing
> Set objFolder = Nothing
> End Sub
> '------------------------
>
> Function DoTheSubFolders(ByRef objFolders As Scripting.Folders, _
> ByRef lngN As Long, ByRef strTitle As String)
> Dim scrFolder As Scripting.Folder
> Dim scrFile As Scripting.File
> Dim lngCnt As Long
>
> For Each scrFolder In objFolders
> For Each scrFile In scrFolder.Files
> If scrFile.Name Like strTitle Then
> Cells(lngN, 2).Value = scrFile.Path
> lngN = lngN + 1
> End If
> Next 'scrFile
>
> 'If there are more sub folders then go back and run function again.
> If scrFolder.SubFolders.Count > 0 Then
> DoTheSubFolders scrFolder.SubFolders, lngN, strTitle
> End If
> Next 'scrFolder
>
> Set scrFile = Nothing
> Set scrFolder = Nothing
> End Function
> '-------------------
>
>
> "Jim Thomlinson" <jamest@xxxxxxxxxxxxxxxxxxxx>
> wrote in message
> news:FC5B6A46-116B-406B-8C34-A4E0E41EFD2A@xxxxxxxxxxxxxxxx
> I would love to spend the time to figure this out on my own but I am in a bit
> of a time crunch. Does anyone have some code for search a given directory and
> all subdirectories for a specific file type (*.xls). Using file system object
> is my preference but I am not too fussy. I would like to return the file name
> and path.--
> HTH...
> Jim Thomlinson
>
.



Relevant Pages

  • Re: Get FileSummaryInfo for files saved on Intranet
    ... Dim objFSO As Scripting.FileSystemObject ... Dim objFolder As Scripting.Folder ... Dim scrFolder As Scripting.Folder ... Dim scrFile As Scripting.File ...
    (microsoft.public.excel.programming)
  • Re: Get FileSummaryInfo for files saved on Intranet
    ... Dim objFSO As Scripting.FileSystemObject ... Dim objFolder As Scripting.Folder ... Dim scrFolder As Scripting.Folder ... Dim scrFile As Scripting.File ...
    (microsoft.public.excel.programming)
  • RE: Get FileSummaryInfo for files saved on Intranet
    ... Dim objFSO As Scripting.FileSystemObject ... Dim objFolder As Scripting.Folder ... Dim scrFolder As Scripting.Folder ... Dim scrFile As Scripting.File ...
    (microsoft.public.excel.programming)
  • Re: objTargetFolder cant move item
    ... attempts in the public folder even though the code tripped the error. ... Dim mstrTargetFolder ... Dim blnFound ... Set objFolders = objNS.Folders ...
    (microsoft.public.outlook.program_forms)
  • objTargetFolder cant move item
    ... I am trying to get the JournalMove custom form downloaded from ... Dim mstrTargetFolder ... Set objFolders = objNS.Folders ...
    (microsoft.public.outlook.program_forms)