Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

  1. Only list out files in this listing rather than files and folders
  2. 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?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer
    
Thanks for the info on the extra flag! Worked perfectly. I agree about the path thing and I don't think I'll really be able to do it. I might look for some sort of batch script RegEx for a replace. –  Mark Nov 23 '09 at 16:20

You can grab the unxutils suite, drop find.exe in your starting directory then launch it with something like:

./find.exe . -type f > result.txt

Just my 2cts.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.