Batch to list files located in .bat location?

December 6, 2011 at 09:35:10
Specs: Windows XP, 4
I am using the following batch to quickly create a list of all of my XML files contained in a folder:

@echo off
dir /b/o "C:\path\location"|find ".xml">ListOfFileNames.txt

The problem with this is I have numerous folder that I want seperate 'ListOfFileNames.txt' files created for, and wanted to know if there was a way to just be able to move the batch file from one file to the next(or just copy/paste into each folder) so that whenever it's run, I do not have to change the path for every file. I would like a batch that just pulls a list of files from whatever location the batch is located.

Any help would be appreciated, thanks!

See More: Batch to list files located in .bat location?

Report •

December 6, 2011 at 14:51:33
You can utilize the %cd% variable to capture the bat files current directory

@echo off
dir %cd% /b /o | find ".xml" >ListOfFileNames.txt

Report •

December 6, 2011 at 15:30:08
Thanks for the quick response. As soon as I posted this question today I figured out how to do it. It's even easier than I thought. The following yields a txt file with every xml in the same folder, and I can just copy and paste it wherever I need:

@echo off
dir /b/o |find ".xml">ListOfFileNames.txt

Thanks again for the help!

Report •
Related Solutions

Ask Question