I am trying to create a batch file to parse a directory Z:\ (not including sub folders) which is a mapped network drive to give all folders that name includes "COMPANY_*" and output those folder names with the the full path to a text file.
The text file will be saved to a program folder location which is referenced when you run the program.
For example
Dir:
Text file:
I started to have a go but dont know what I am doing and need to run this batch on 10 computers so do not want to cause any problems.
dir "Z:\" /b >d:\test.txt
FOR /F "delims=" %%a in (test.txt) do @echo Z:\%%a>>output.txt
del "d:\test.txt"
start C:\Windows\System32\notepad.exe "d:\output.txt"
pause
Right-click that folder and select Show more options. Click Copy File List to Clipboard on the classic menu. You'll still need to paste the copied list into a text file. Launch Run, type Notepad in the Open box, and click OK.
You can use the DIR command by itself (just type “dir” at the Command Prompt) to list the files and folders in the current directory.
The ls command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.
cd Z:\
for /D %%A IN ("COMPANY_*") DO echo "Z:\%%A">>D:\output.txt
You can add a call to open the file with notepad if you want to. What you have now would work.
It looks like you can get the folders that you want with no intermediate filtering:
dir Z:\Company_* /b /a:d >output.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With