I want to create a batch file. When it is invoked as batch.bat MyProject or batch.bat MyProject/ it will produce the following list. Note that Dir is a sub directory of MyProject. I am using Windows 7.
Dir
Dir/SubDir1
Dir/SubDir1/SubSubDir1
Dir/SubDir1/SubSubDir2
Dir/SubDir2
Dir/SubDir2/SubSubDir1
Dir/SubDir2/SubSubDir2
Dir/SubDir2/SubSubDir3
Dir/SubDir3
Dir/SubDir4
How to write a list of directory trees to a text file?
File names must be excluded.
FORFILES provides a simple solution, but it is SLOW. The command works equally well from within a batch file or on the command line:
If you run the command with MyProject as your current directory then you can drop the
/p "c:\MyProject"option from the command.If you don’t mind your relative paths being enclosed in quotes with
.\in the front of each path, then the solution is even simpler: