@echo off setlocal enabledelayedexpansion :: Output CSV file name set output_file=file_metadata.csv :: Write the CSV header echo Filename,File Date (YYYY-MM-DD),File Time (HH:MM:SS)> "%output_file%" :: Loop through all files in the directory for %%F in (*) do ( :: Extract the file date and time for /f "tokens=1-3 delims=/ " %%A in ("%%~tF") do ( set file_date=%%C-%%A-%%B set file_time=%%~tF for /f "tokens=1-2 delims= " %%D in ("!file_time!") do set file_time=%%E ) :: Append file details to the CSV echo %%F,!file_date!,!file_time!>> "%output_file%" ) echo File metadata exported to "%output_file%". pause