Windows 7 forum


Problem with FOR command - need to run on subdirectories

by comphelp402 / June 8, 2011 5:49 AM PDT

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?


Discussion is locked
You are posting a reply to: Problem with FOR command - need to run on subdirectories
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: 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.

All Answers

Collapse -
Odd. Why won't the /S on DIR do for this?
by R. Proffitt Forum moderator / June 8, 2011 8:40 AM PDT

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

Collapse -
What Bob suggested id how I would suggest too
by Edward ODaniel / June 8, 2011 11:09 AM PDT

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.

Popular Forums
Computer Newbies 10,686 discussions
Computer Help 54,365 discussions
Laptops 21,181 discussions
Networking & Wireless 16,313 discussions
Phones 17,137 discussions
Security 31,287 discussions
TVs & Home Theaters 22,101 discussions
Windows 7 8,164 discussions
Windows 10 2,657 discussions


Help, my PC with Windows 10 won't shut down properly

Since upgrading to Windows 10 my computer won't shut down properly. I use the menu button shutdown and the screen goes blank, but the system does not fully shut down. The only way to get it to shut down is to hold the physical power button down till it shuts down. Any suggestions?