arskiracer
New Member
- Joined
- Apr 3, 2013
- Messages
- 18
I currently have the following code to load all file names and paths into my workbook:
I have about 60,000 file names and paths that need to be written into the outputsheet. The above code is executed recursively for all the directory locations that I want to search. I would like to make the code faster and the only thing I can think of is to combine this "Split" line:
with this line that writes the file name to the spreadsheet:
This is as close as I can get, but this would only return the number of items, not the actual file name:
Anyone have any ideas about how I can combine these two lines? If anyone sees any other ways to improve the efficiency of my code, please let me know. Thank you for the help,
Adrian
Code:
For Each File In fld.Files
DoEvents 'allow other processes to execute
TotalFileCount = TotalFileCount + 1 'increment file counter
TempPath = Split(File, "\") 'grab file name instead of entire path
Worksheets(OutputSheet).Cells(OutputRow, 1).Value = TempPath(UBound(TempPath))
Worksheets(OutputSheet).Cells(OutputRow, 2).Value = File
OutputRow = OutputRow + 1
Application.StatusBar = "Elapsed Time: " & Format(Now - StartTime, "hh:mm:ss") _
& " Searching Directories... " & TotalFileCount & " files found so far"
Next File
I have about 60,000 file names and paths that need to be written into the outputsheet. The above code is executed recursively for all the directory locations that I want to search. I would like to make the code faster and the only thing I can think of is to combine this "Split" line:
Code:
TempPath = Split(File, "\")
with this line that writes the file name to the spreadsheet:
Code:
Worksheets(OutputSheet).Cells(OutputRow, 1).Value = TempPath(UBound(TempPath))
This is as close as I can get, but this would only return the number of items, not the actual file name:
Code:
Worksheets(OutputSheet).Cells(OutputRow, 1).Value = Ubound(Split(File, "\"))
Anyone have any ideas about how I can combine these two lines? If anyone sees any other ways to improve the efficiency of my code, please let me know. Thank you for the help,
Adrian
Last edited: