Help w/ batch file to output dir listings in subdirectories

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
machone
Posts: 31
Joined: 01 Oct 2012 18:36

Help w/ batch file to output dir listings in subdirectories

#1 Post by machone » 03 Jan 2014 14:59

I've got a folder hierarchy in which I need to create a directory listing inside each main folder, showing the result of "dir /b /s *.* > index.txt".

For example, in

root folder
root folder\main_folder_1\some_more_subfolders\files
root folder\main_folder_2\some_more_subfolders\files

I need to be able to run a batch from within \root folder\. That batch needs to deposit a separate index.txt file into each \main_folder_#\ containing the contents of \main_folder_#\ and its subfolders. I've been able to output a main directory index.txt file into \root folder\ but I can't figure out how to deposit separate index.txt files into each \main_folder_#\ branch. Any help would be appreciated!

m1

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Help w/ batch file to output dir listings in subdirector

#2 Post by foxidrive » 03 Jan 2014 17:52

Code: Select all

@echo off
for /d %%a in (*) do dir "%%a" /b /s >"%%a\index.txt"

machone
Posts: 31
Joined: 01 Oct 2012 18:36

Re: Help w/ batch file to output dir listings in subdirector

#3 Post by machone » 04 Jan 2014 10:53

Very nice, thanks for that. It works great!

I wonder, is there any way to eliminate the 'higher' level directories from what is recorded in the output file? For example, if the batch is run from:
e:\Archive\Images\January\

and it's recording the following path, as an example:
e:\Archive\Images\January\Exterior\Resource\Image_001.tif

Then the path stored in the output.txt would read:
\Exterior\Resource\Image_001.tif

and eliminate all of the path "above" the directory from which it was run...?

m1

Post Reply