Question

Problem with FOR command - need to run on subdirectories

I need to make a batch file that will produce a list of all the files in several subdirectories, showing which subdirectory each file is in.

I've tried using the FOR command but MS's instructions and examples are no help. Here's what I tried:

for /r in (X:\DOCS\Main\Chapters) do dirGREATERTHANSIGNfilelist.txt
(between the "dir" and "filelist.txt" above is supposed to be the symbol above the period on my keyboard, but it's not appearing correctly in this post)

No matter what I enter between the parenthesis it doesn't work. Suggestions?

Thanks.

Discussion is locked
Follow
Reply to: Problem with FOR command - need to run on subdirectories
PLEASE NOTE: Do not post advertisements, offensive materials, profanity, or personal attacks. Please remember to be considerate of other members. If you are new to the CNET Forums, please read our CNET Forums FAQ. All submitted content is subject to our Terms of Use.
Reporting: Problem with FOR command - need to run on subdirectories
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Comments
- Collapse -
Answer
Odd. Why won't the /S on DIR do for this?

And there are other interesting switches such as /B and more.
Bob

- Collapse -
Answer
What Bob suggested id how I would suggest too

using your example that would be -
dir /s X:\DOCS\Main\Chapters > filelist.txt to get a list of all files in ..\Chapters and any sub directories within it.

dir /s X:\DOCS\Main\ > filelist.txt to get a list of all files in ..\Main and all its sub directories.

open a command prompt and type dir /? to see all the switches available for refining your listing.

CNET Forums