The below scripts allows you to select a folder and generate a CSV report detailing the below file properties of all of the file in that folder and the folders sub folders.
- Path
- Name
- Size
- File Type
- Date Created
- Date Last Access
- Date Last Modified
How to use:
1) Download the attached script or copy and save the below as something like report_file_properties.vbs
2) Run the script
3) Use the dialog to browse the folder you want to report on and press OK
4) Wait, the script may that a while to run depending on the number of files in the folder and sub folders. When it is complete you will get a message like the below.
The report will be created in the same directory as the script
5) Press Yes to see the report which should look something like the below.
The script:
Dim objFSO, startFolder, OlderThanDate 'Flags for files Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 ' Flags for browse dialog Const BIF_returnonlyfsdirs = &H0001 Const BIF_dontgobelowdomain = &H0002 Const BIF_statustext = &H0004 Const BIF_returnfsancestors = &H0008 Const BIF_editbox = &H0010 Const BIF_validate = &H0020 Const BIF_browseforcomputer = &H1000 Const BIF_browseforprinter = &H2000 Const BIF_browseincludefiles = &H4000 currentScriptPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") reportFile = currentScriptPath & "FilePropertiesReport.csv" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objDlg = WScript.CreateObject("Shell.Application") Set objShell = CreateObject("WScript.Shell") ' Use the BrowseForFolder method. Set objStartFolder = objDlg.BrowseForFolder (&H0, _ "Select the folder you want to report on, su folder will also be reported", BIF_editbox + BIF_returnonlyfsdirs) ' Here we use TypeName to detect the result. If InStr(1, TypeName(objStartFolder), "Folder") > 0 Then startFolder = objStartFolder.ParentFolder.ParseName(objStartFolder.Title).Path 'Create report file and add CSV Header Set objReportFile = objFSO.CreateTextFile(reportfile, ForWriting) objReportFile.Write("Path, Name, Size (kb), Type, Date Created, Date Last Accessed, Date Laste Modified" & chr(13) & chr(10)) 'Run the function ReportFiles startFolder 'Close the report objReportFile.Close 'Ask to open the report now or just close strMbox = MsgBox("Reporting Complete. " & chr(13) & chr(10) &"The report has been saved to: " & reportFile & chr(13) & chr(10) & chr(13) & chr(10) & "Would you like to open the report now?",4,"Open report now?") if strMbox = 6 Then objShell.Run reportFile End if Else MsgBox "An error has occured." End if '---------------------------------------------- ' Function '---------------------------------------------- Function ReportFiles(folderName) Dim objFolder, objFile, fileCollection, folderCollection, subFolder Set objFolder = objFSO.GetFolder(folderName) Set fileCollection = objFolder.Files For Each objFile In fileCollection strFilePath = chr(34) & objFile.Path & chr(34) strFileName = chr(34) & objFile.Name & chr(34) strFileSize = objFile.Size / 1024 strFileType = chr(34) & objFile.Type & chr(34) strFileDateCreated = objFile.DateCreated strFileDateLastAccessed = objFile.DateLastAccessed strFileDateLastModified = objFile.DateLastModified objReportFile.Write(strFilePath & "," & strFileName & "," & strFileSize & "," & strFileType & "," & strFileDateCreated & "," & strFileDateLastAccessed & "," & strFileDateLastModified & chr(13) & chr(10)) Next 'Loop for each sub folder Set folderCollection = objFolder.SubFolders For Each subFolder In folderCollection ReportFiles subFolder.Path Next End Function
Sorry, if I’ve commented twice on this – but I was wondering how the script might be modified to add properties, such as GPS location from a JPEG file in particular, to the fields that are exported to the CSV file.
Best script I’ve come across for this, thanks – *high five*
Hi,
You’re fantastic! I’m wondering if you could add the document property “Title” to the script AND if a user could populate the “Title” field in the report, created by your script AND have the report imported back into the folder, to update the “title” document property for all the files.
Is this asking too much? 🙂
This script worked for most of the folders but for a folder which had user profiles it is throwing an error for the below line in the script.
Line for which script is throwing error
objReportFile.Write(strFilePath & "," & strFileName & "," & strFileSize & "," & strFileType & "," & strFileDateCreated & "," & strFileDateLastAccessed & "," & strFileDateLastModified & chr(13) & chr(10))
Error
Folder-File-Details.vbs(144, 1) Microsoft VBScript runtime error: Invalid procedure call or argument
I also tried to run the script with Cscript with a admin CMD window.