kathy
kathy

Reputation: 11

Batch file to print list of directory folders and files from a specific subfolder

Please bear with me, I'm a noob to batch files.

So I'm using D:\RDSUsers as my main directory. There are about 150 folders in here (each has a name of a user, for example mine is k.suria ) and I want to look into each user Folder and choose their "Support System" folder that is inside their Desktop Folder. Sounds a bit tricky.

For example my user folder is in D:\RDSUsers\k.suria and I want to get what ever is in my D:\RDSUsers\k.suria\Desktop\System Support folder

In other words I want to to list the Folder names in D:\RDSUsers (150 of them) and list all the files that are in the "System Support" folder that is in everyones Desktop folder, but I want it in one text file.

Did I confuse anyone?

So far I have this:

for /d %%x in (D:\RDSUsers\ *) Do dir %%x\desktop\"Support Systems" > %%x.txt

This prints a 150 text files for each folder from D:\RDSUsers and it lists everything that is in the "Support Systems" folder. The problem is I dont want 150 text files, I'd like just one. How do I get it to print only one text file?

Thanks in advance for your help!

Upvotes: 1

Views: 2984

Answers (1)

Kevin
Kevin

Reputation: 8561

You're so close. Just change the end so that you don't make a new file name each time, and add a second > so that the output is appended to the existing file:

for /d %%x in (D:\RDSUsers\*) Do dir %%x\desktop\"Support Systems" >> OneBigFile.txt

Edit: Okay, to get the user/folder name followed by a list of files all on one line, this should do the trick:

setlocal enabledelayedexpansion
for /d %%x in (D:\RDSUsers\*) do (
    set line=%%~nx
    for %%y in (%%x\desktop\"Support Systems"\*) do set line=!line! %%~nxy  
    echo !line! >> output.txt
)

Upvotes: 1

Related Questions