Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting names of files in subdirectories
The following procedures will loop through a specified directory and
pull all the file names. Is there a way to adjust this code to loop through a directory and all of it's subdirectories and pull the file names and paths. TIA David Sub Get_File_Names(SearchDir As String) Dim FoundFiles Dim FileName As String Index = 1 FoundFiles = DirList(SearchDir) End Sub Function DirList(Indir As String) Dim FileMatrix(1 To 500) On Error Resume Next ListFile = Dir(Indir) ' Index = 1 Do While Not ListFile = "" FileMatrix(Index) = ListFile Range("SourceFiles1").Rows(Index).Value = Indir & ListFile Index = Index + 1 ListFile = Dir() Loop End Function |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting names of files in subdirectories
Dim RowNumber Sub GetFolderSize() strFolder = "C:" RowNumber = 1 Set fso = CreateObject _ ("Scripting.FileSystemObject") Set folder = _ fso.GetFolder(strFolder) Sheets(1).Cells(RowNumber, 1) = strFolder + "\" Sheets(1).Cells(RowNumber, 2) = folder.Size RowNumber = RowNumber + RowNumber Call GetSubFolder(strFolder + "\") End Sub Sub GetSubFolder(strFolder) Set fso = CreateObject _ ("Scripting.FileSystemObject") Set folder = _ fso.GetFolder(strFolder) If folder.subfolders.Count 0 Then For Each sf In folder.subfolders On Error GoTo 100 Call GetSubFolder(strFolder + sf.Name + "\") 100 Next sf End If 'folder size in bytes On Error GoTo 200 For Each fl In folder.Files Sheets(1).Cells(RowNumber, 3) = fl.DateLastModified Sheets(1).Cells(RowNumber, 2) = fl.Size Sheets(1).Cells(RowNumber, 1) = strFolder & fl.Name RowNumber = RowNumber + 1 Next fl 200 On Error GoTo 0 End Sub "David" wrote: The following procedures will loop through a specified directory and pull all the file names. Is there a way to adjust this code to loop through a directory and all of it's subdirectories and pull the file names and paths. TIA David Sub Get_File_Names(SearchDir As String) Dim FoundFiles Dim FileName As String Index = 1 FoundFiles = DirList(SearchDir) End Sub Function DirList(Indir As String) Dim FileMatrix(1 To 500) On Error Resume Next ListFile = Dir(Indir) ' Index = 1 Do While Not ListFile = "" FileMatrix(Index) = ListFile Range("SourceFiles1").Rows(Index).Value = Indir & ListFile Index = Index + 1 ListFile = Dir() Loop End Function |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting names of files in subdirectories
Works Perfectly!!!!
Thank you. David |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
All Subdirectories | Excel Programming | |||
import few text files from subdirectories | Excel Programming | |||
list of all subdirectories in a given directory in excel | Excel Worksheet Functions | |||
Subdirectories | Excel Programming | |||
Change names of files in a folder to match names in Excel Column | Excel Programming |