VBS - Get list of files and generate a CSV
Need a file list in CSV format? Use this VBScript to scan a folder, including sub-folders, and output file details like size, date, and owner for easy analysis.
This article is over a year old but was reviewed on July 30, 2026 — the content is still accurate.
This article is part of the VBA & MS Office automation series:
- MS Office - How to create a ribbon in Excel
- MS Excel - How to call a SOAP web service
- How to optimize an existing MS Access database
- VBS - Retrieve the list of fields in a MS Access Database
- VBS - Auto update script
- Microsoft Outlook - VBA - Save emails as PDF
- VBS - Get list of files and generate a CSV
- MS Office - Load dropdown from Excel's range
- Export MS Access objects
- MS Excel - Get the list of references used in your modules

This article shares a VBScript (files2csv.vbs) that recursively scans a Windows folder and exports file details — path, name, creation/access/modified dates, size, type, and owner — to a CSV file, ready for further analysis in Excel or Python/Pandas.
Six years ago, I needed a DOS script that would allow me to find the list of every file in a folder on a Windows machine and generate a .csv file with that list.
Once the .csv file had been generated, I could then process it in MS Excel, for example, and sort/filter it or, why not, in Python using the Pandas library.
Here's what this script produces: a CSV file listing every file in a folder, with dates, size, type, and owner.
"FilePathAndName";"ParentFolder";"Name";"DateCreated";"DateLastAccessed";"DateLastModified";"Size";"Type";"Suffix";"Owner";
"C:\temp\test\test.csv";"C:\temp\test";"test.csv";"21-01-24 09:07:44";"21-01-24 09:09:08";"21-01-24 09:09:08";"472";"CSV Microsoft Excel File";"csv";"Christophe";
"C:\temp\test\test.vbs";"C:\temp\test";"test.vbs";"21-01-24 08:43:49";"21-01-24 09:09:03";"21-01-24 09:09:03";"3246";"VBScript File";"vbs";"Christophe";
Here's the script that generates it. Copy/paste the source below and save it to a file, let's say c:\files2csv.vbs. Start a DOS console, run cd c:\ then cscript files2csv.vbs. When the job has been done, you'll get the listing in files2csv.csv.
'------------------------------------------------------------'' Get the list of files of the current folder + sub-folders and' generate a .csv file with file information like path, size,' extensions, author, ... making then easy to work with that list' in Excel'' Based on a script of' @author Peter Pinchao Liu (https://github.com/lpcclown)' then modified by Christophe Avonture'' @Link : https://github.com/lpcclown/fileScan''------------------------------------------------------------
Option Explicit
Dim objFSO, objCSVFile
' ------------------------------------' Loop all file under one folder' ------------------------------------Function FilesTree(sPath)
Dim objFolder, objSubFolders, objSubFolder, objFiles, objFileDim objShellDim strFileName
Set objFolder = objFSO.GetFolder(sPath) Set objSubFolders = objFolder.SubFolders Set objFiles = objFolder.Files
For Each objFile In objFiles objCSVFile.Write chr(34) & objFile.Path & chr(34) & ";" objCSVFile.Write chr(34) & objFile.ParentFolder & chr(34) & ";" objCSVFile.Write chr(34) & objFile.Name & chr(34) & ";" objCSVFile.Write chr(34) & objFile.DateCreated & chr(34) & ";" objCSVFile.Write chr(34) & objFile.DateLastAccessed & chr(34) & ";" objCSVFile.Write chr(34) & objFile.DateLastModified & chr(34) & ";" objCSVFile.Write chr(34) & objFile.Size & chr(34) & ";" objCSVFile.Write chr(34) & objFile.Type & chr(34) & ";" objCSVFile.Write chr(34) & objFSO.getextensionname(objFile.Path) & chr(34) & ";"
' Get file owner Set objShell = CreateObject ("Shell.Application") Set objFolder = objShell.Namespace (sPath)
For Each strFileName in objFolder.Items if objFolder.GetDetailsOf (strFileName, 0) = objFile.Name Then objCSVFile.Write chr(34) & objFolder.GetDetailsOf (strFileName, 10) & chr(34) & ";" End If Next
objCSVFile.Writeline
Next
For Each objSubFolder In objSubFolders FilesTree(objSubFolder.Path) ' Recursion Next
Set objFiles = Nothing Set objSubFolders = Nothing Set objFolder = Nothing
End Function
Dim sResultFileName, sFolderNameDim wshShell
Const ForWriting = 2
' Create new CSV file : same name of this script but with ' .csv extension sResultFileName = wScript.ScriptFullName sResultFileName = replace(sResultFileName, ".vbs", ".csv")
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objCSVFile = objFSO.CreateTextFile(sResultFileName, ForWriting, True)
' Write comma delimited list of columns in new CSV file. objCSVFile.Write chr(34) & "FilePathAndName" & chr(34) & ";" & _ chr(34) & "ParentFolder" & chr(34) & ";" & _ chr(34) & "Name" & chr(34) & ";" & _ chr(34) & "DateCreated" & chr(34) & ";" & _ chr(34) & "DateLastAccessed" & chr(34) & ";" & _ chr(34) & "DateLastModified" & chr(34) & ";" & _ chr(34) & "Size" & chr(34) & ";" & _ chr(34) & "Type" & chr(34) & ";" & _ chr(34) & "Suffix" & chr(34) & ";" & _ chr(34) & "Owner" & chr(34) & ";"
objCSVFile.Writeline
Set wshShell = CreateObject("WScript.Shell") sFolderName = wshShell.CurrentDirectory Set wshShell = Nothing
wScript.echo "Scan the " & sFolderName & ", please wait..." wScript.echo ""
FilesTree(sFolderName)
wScript.echo "Done, file " & sResultFileName & " has been created"This VBScript scans a folder and all its subfolders to collect information about every file it finds, then writes that data to a CSV file that can be opened in Excel. For each file, it records details like path, size, file type, dates, and owner so you can easily analyze your files in a spreadsheet.
Did you need tab delimited?
If so, just make a search & replace to change ";" to vbTab everywhere.
This article is part of the VBA & MS Office automation series:
- MS Office - How to create a ribbon in Excel
- MS Excel - How to call a SOAP web service
- How to optimize an existing MS Access database
- VBS - Retrieve the list of fields in a MS Access Database
- VBS - Auto update script
- Microsoft Outlook - VBA - Save emails as PDF
- VBS - Get list of files and generate a CSV
- MS Office - Load dropdown from Excel's range
- Export MS Access objects
- MS Excel - Get the list of references used in your modules





