I have a simple batch script that recursively looks at all files and folders within the directory and writes out the file inventory to a text file. It currently looks like this:
dir /b/s > files.txt
The /b
means don't give any extra info and /s
makes it recursive within sub-folders. The sample output is:
C:\Users\mark\Desktop\site\site\Web
C:\Users\mark\Desktop\site\site\Web\Themes
C:\Users\mark\Desktop\site\site\Web\Themes\Sitev2
C:\Users\mark\Desktop\site\site\Web\Themes\Sitev2\images
C:\Users\mark\Desktop\site\site\Web\Themes\Sitev2\style
C:\Users\mark\Desktop\site\site\Web\Themes\Sitev2\images\site
C:\Users\mark\Desktop\site\site\Web\Themes\Sitev2\images\site\beta.gif
C:\Users\mark\Desktop\site\site\Web\Themes\Sitev2\style\site.css
C:\Users\mark\Desktop\site\site\Web\Themes\Sitev2\style\ie7.css
I'd like two things:
- Only list out files in this listing rather than files and folders
- I'd like the paths to be relative from where the batch script was called
E.g. I have the script in the C:\Users\mark\Desktop\site\site\
folder so I don't want to see up to that point.
Is it possible to do those two things and if so, can anyone help with either?
You can grab the unxutils suite, drop find.exe in your starting directory then launch it with something like:
Just my 2cts.
dir /b /s /a-d
will get you files only. I think for relative paths you're going to need to do some more work than just a simple batch file, e.g. call some vbscript to (1) get the current directory, (2) open the text file, (3) do a search and replace on the text file, and (4) save the result back.