Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Getting names of files in subdirectories

Works Perfectly!!!!

Thank you.

David

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
All Subdirectories Jim Thomlinson[_4_] Excel Programming 10 July 3rd 07 09:50 PM
import few text files from subdirectories bratek Excel Programming 7 July 26th 06 01:14 PM
list of all subdirectories in a given directory in excel Peter STEVENS Excel Worksheet Functions 3 February 11th 06 03:32 PM
Subdirectories Skip[_4_] Excel Programming 4 August 31st 04 05:59 PM
Change names of files in a folder to match names in Excel Column saybut Excel Programming 4 February 9th 04 06:26 PM


All times are GMT +1. The time now is 08:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"