问题
We are finalising a legal matter and need to provide a list of all correspondence for the matter. I've got a folder on my computer with ALL of the emails, word docs, pdf's, jpg's etc. and wish to quickly create a spreadsheet listing the file name, type, size, data created.
Can this be done with a batch file? If so, how?
回答1:
This is a basic version that should get you going.
It uses for
to collect info about files in a folder (and all subfolders), outputting as csv.
You could adjust (or ask for help in adjusting), such as making pretty names for the file type. The timestamp this batch gives you is 'date modified' rather than 'date created'. If that's critical we can work around that too.
@echo off
setlocal
set DATA_DIR=%1
if not defined DATA_DIR (
echo You must specify a folder with your data files.
exit /b 1
)
echo FILE, TYPE, SIZE, TIMESTAMP
for /f "delims=" %%f in ('dir /s /b /a-d %DATA_DIR%') do (
echo %%~f, %%~xf, %%~zf, %%~tf
)
To use:
C:\...\> make_csv.cmd c:\data > FileList.csv
And you will get something like FileList.csv:
FILE, TYPE, SIZE, TIMESTAMP C:\data\that one.doc, .doc, 0, 10/05/2013 11:14 AM C:\data\this one.txt, .txt, 6, 10/05/2013 11:14 AM C:\data\sub\another.jpg, .jpg, 6, 10/05/2013 11:15 AM
来源:https://stackoverflow.com/questions/16473587/spreadsheet-of-all-files-in-a-directory