Currently I have a FileListGenerator.bat which looks like so:
dir /b /s >>FilesDirectoryList.txtReturning a list of file directories looking like.
C:\Users\Ben\Desktop\Customers\Customer1
C:\Users\Ben\Desktop\Customers\Customer2
C:\Users\Ben\Desktop\Customers\FileListGenerator.bat
C:\Users\Ben\Desktop\Customers\FilesDirectoryList.txt
C:\Users\Ben\Desktop\Customers\Customer1\Analysys Mason
C:\Users\Ben\Desktop\Customers\Customer1\More
C:\Users\Ben\Desktop\Customers\Customer1\Other
C:\Users\Ben\Desktop\Customers\Customer1\Analysys Mason\Crook _ Hatchet blk white font.psd
C:\Users\Ben\Desktop\Customers\Customer1\More\Crook _ Hatchet lot.png
C:\Users\Ben\Desktop\Customers\Customer1\More\Crook _ Hatchet midd.png
C:\Users\Ben\Desktop\Customers\Customer1\Other\Crook _ Hatchet bigger.png
C:\Users\Ben\Desktop\Customers\Customer1\Other\Crook _ Hatchet botton final.png
C:\Users\Ben\Desktop\Customers\Customer2\Analysys Mason
C:\Users\Ben\Desktop\Customers\Customer2\More
C:\Users\Ben\Desktop\Customers\Customer2\Other
C:\Users\Ben\Desktop\Customers\Customer2\Analysys Mason\LiberalHand-Bld.otf
C:\Users\Ben\Desktop\Customers\Customer2\Analysys Mason\LiberalHand-Rg.ttf
C:\Users\Ben\Desktop\Customers\Customer2\Other\Crook _ Hatchet new font.pngIs there a way to either run a script against the .txt file or in command line to return just the file names?
33 Answers
Try this in command line:
for /r %a in (*) do @echo %~nxa >>FilesDirectoryList.txtIn batch file (need to double the percentage signs):
for /r %%a in (*) do @echo %%~nxa >>FilesDirectoryList.txtBased on answer here
13If you need to display ONLY a certain filetype like .txt, .doc, .dll, .exe ..etc, you can use dir command and adjust the parameters as you need.
Here is a simple example: Suppose I need to display a list of text files names only in a directory. I can use this command
dir *.txt /b
and it'll display something like this :
file1.txt
file2.txt
file3.txt
file4.txt
...etc
you can use it in a batch file as is, (something like this):
@Echo off
:: display a list of *.txt files
dir *.txt /bor you can expand the code as you wish ( something like this):
@Echo off
:: save a list of *.txt files into another text file inside C:
dir *.txt /b > C:\results.txtIt depends on your goal and how you want to achieve it.
You can learn more about DIR command line from here : (v=ws.11).aspx
In Windows PowerShell, you can do this.
Just the file names with full path:
(gci -r | ? {!$_.PsIsContainer}).FullName | Out-File test.txt -ForceJust the file names showing the name and extension only:
(gci -r | ? {!$_.PsIsContainer}).Name | Out-File test.txt -Force 6