Dear MrExcel Experts,
I am an intern trying to catalog over 100K old files. I am using a main worksheet to specify the parameters of what files I need. The parameters include specifying which drive I want to search, if I want to include Subfolders, specifying a date to gather files prior to, and specifying folders not to search. The code references cells from a main worksheet and adds the gathered files to a new sheet. HEre is the code I have so far:
Sub ListFiles2()
On Error Resume Next
Call Setup2
Call CreateList
End Sub
Sub CreateList()
Dim filePath As Variant, fsObject As Variant, file As Variant
Dim i As Long
With Application.FileSearch
.LookIn = "C:\Documents and Settings\pawest\My Documents\"
.SearchSubFolders = True
.Filename = "*.*"
.Execute
For Each filePath In .FoundFiles
i = i + 1
Set fsObject = CreateObject("Scripting.FileSystemObject")
Set file = fsObject.GetFile(filePath)
ActiveSheet.Cells(i, 1) = file.Drive
ActiveSheet.Cells(i, 2) = file.Name
ActiveSheet.Cells(i, 3) = file.ParentFolder
ActiveSheet.Cells(i, 4) = file.Path
ActiveSheet.Cells(i, 5) = file.DateLastModified
Next filePath
.NewSearch
End With
End Sub
Sub Setup2()
Sheets.Add
Cells(1, 1) = "Drive"
Cells(1, 2) = "File Name"
Cells(1, 3) = "Parent Folder"
Cells(1, 4) = "Path"
Cells(1, 5) = "Date Last Modified"
Range("A1:E1").Font.Bold = True
End Sub
I know how to reference a cell to search a drive and I know how to reference a cell to searchsubfolders. But now I need to make it so it can reference cells from the worksheet using loops to specify a date in the past in which I want to search for old files and then multiple cells that include multiple folders for which not to search. I have used multipe If-Then, and Select Case loops, but I am a novice VBA user and nothing seems to work. I am using EXCEL 2003 by the way.
After I have completed this code. I will need to also move the files and then delete the files from their previous location. Any insight would be much appreciated! Thanks!
I am an intern trying to catalog over 100K old files. I am using a main worksheet to specify the parameters of what files I need. The parameters include specifying which drive I want to search, if I want to include Subfolders, specifying a date to gather files prior to, and specifying folders not to search. The code references cells from a main worksheet and adds the gathered files to a new sheet. HEre is the code I have so far:
Sub ListFiles2()
On Error Resume Next
Call Setup2
Call CreateList
End Sub
Sub CreateList()
Dim filePath As Variant, fsObject As Variant, file As Variant
Dim i As Long
With Application.FileSearch
.LookIn = "C:\Documents and Settings\pawest\My Documents\"
.SearchSubFolders = True
.Filename = "*.*"
.Execute
For Each filePath In .FoundFiles
i = i + 1
Set fsObject = CreateObject("Scripting.FileSystemObject")
Set file = fsObject.GetFile(filePath)
ActiveSheet.Cells(i, 1) = file.Drive
ActiveSheet.Cells(i, 2) = file.Name
ActiveSheet.Cells(i, 3) = file.ParentFolder
ActiveSheet.Cells(i, 4) = file.Path
ActiveSheet.Cells(i, 5) = file.DateLastModified
Next filePath
.NewSearch
End With
End Sub
Sub Setup2()
Sheets.Add
Cells(1, 1) = "Drive"
Cells(1, 2) = "File Name"
Cells(1, 3) = "Parent Folder"
Cells(1, 4) = "Path"
Cells(1, 5) = "Date Last Modified"
Range("A1:E1").Font.Bold = True
End Sub
I know how to reference a cell to search a drive and I know how to reference a cell to searchsubfolders. But now I need to make it so it can reference cells from the worksheet using loops to specify a date in the past in which I want to search for old files and then multiple cells that include multiple folders for which not to search. I have used multipe If-Then, and Select Case loops, but I am a novice VBA user and nothing seems to work. I am using EXCEL 2003 by the way.
After I have completed this code. I will need to also move the files and then delete the files from their previous location. Any insight would be much appreciated! Thanks!