Get a listing of file names and paths
I have a directory with several sub-directories and I am trying to get a list of the file names and their path, and then I would like to have this data in Excel. Is there a way I can do this with the command line in Windows 7?
Desired Excel result:
A1: FILENAME.JPG B1: X:\DIR1\DIR2\FIELNAME.JPG
echo off & for %i in (*) do dir %i /b & dir .\%i /s /b
That will produce the following in a directory named foo with files a, b and c:
a c:\foo\a b c:\foo\b c c:\foo\c
So just pipe the output to a file then import that into Excel. You'll have to do some manipulations in Excel to get the lines into two columns instead of rows, but that shouldn't be difficult.
To pipe it correctly, you need to remember to pipe both dir commands and append to the file, like this:
echo off & for %i in (*) do dir %i /b >> foo.csv & dir .\%i /s /b >>foo.csv