Batch file to display all folders in a directory and output to txt with

I am trying to create a batch file for parsing the Z: \ directory (not including subfolders), which is a mapped network drive, to give all the folders whose names include "COMPANY_ *" and output these folder names with the full path to the text file.

The text file will be saved in the folder with the program folder that is referenced when the program starts.

for instance

Dir:

  • Z: \ Company_001
  • Z: \ Protection
  • Z: \ Comapny_002
  • Z: \ Company_101

Text file:

  • Z: \ Company_001
  • Z: \ Company_002
  • Z: \ Company_101

I started working, but I don’t know what I’m doing, and I need to run this batch on 10 computers so that there are no 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
+5
source share
2 answers
cd Z:\
for /D %%A IN ("COMPANY_*") DO echo "Z:\%%A">>D:\output.txt

, , . .

+7

, :

dir Z:\Company_* /b /a:d >output.txt
+6

All Articles