Hi all,
I am looking for a way to loop through a directory (including subfolders) and record every file name, last modified date but most importantly (and proving most difficult) who was the last person/user to modify the file.
I have got to this point:
Option Explicit
Sub ListFiles()
Application.ScreenUpdating = False
Dim objFSO As Scripting.FileSystemObject
Dim objTopFolder As Scripting.Folder
Dim strTopFolderName As String
Range("A1").Value = "File Name"
Range("B1").Value = "File Size"
Range("C1").Value = "File Type"
Range("D1").Value = "Date Created"
Range("E1").Value = "Date Last Accessed"
Range("F1").Value = "Date Last Modified"
strTopFolderName = "C:\Documents and Settings\User\My Documents\Test Directory\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTopFolder = objFSO.GetFolder(strTopFolderName)
Call RecursiveFolder(objTopFolder, True)
Columns.AutoFit
Application.ScreenUpdating = True
End Sub
Sub RecursiveFolder(objFolder As Scripting.Folder, _
IncludeSubFolders As Boolean)
Dim objFile As Scripting.file
Dim objSubFolder As Scripting.Folder
Dim NextRow As Long
NextRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
For Each objFile In objFolder.Files
Cells(NextRow, "A").Value = objFile.Name
Cells(NextRow, "B").Value = objFile.Size
Cells(NextRow, "C").Value = objFile.Type
Cells(NextRow, "D").Value = objFile.DateCreated
Cells(NextRow, "E").Value = objFile.DateLastAccessed
Cells(NextRow, "F").Value = objFile.DateLastModified
NextRow = NextRow + 1
Next objFile
If IncludeSubFolders Then
For Each objSubFolder In objFolder.SubFolders
Call RecursiveFolder(objSubFolder, True)
Next objSubFolder
End If
End Sub
This works fine but what I can't achieve in a similar way is the actual name of the person who last modified/accessed the file (happy for this to be a PC generated ID, can use a lookup table). This is further complicated by the fact that the files within the directory will be a mixture of Office files, mainly xls ppt and doc.
Is this at all possible either through amending my code or using a completely new solution? The directory also may grow over time and I'm conscious this code may take a while to run. Am I missing a more efficient solution?
Appreciate any help.
Regards
Alex
Bookmarks