问题
1.
Searched everywhere, I do find tutorials to print list of files in directory and sub directories using dir command as follows:
@echo off
dir /S > list.txt
pause
Above code will return all files in list.txt. We can use switches to get lists in various formats.
What I am trying to do is:
When I run batch file output file list.txt should be placed in all Sub Directories and not only in the directory from batch file is being executed.
2.
I am trying to to rename list.txt as %current directory name%.txt and having no clues to achieve that.
回答1:
This uses the for variable modifiers as the directory it needs to write the list.txt file.
del /s list.txt
for /F "delims=" %%G IN ('dir /b /s') DO @echo "%%G">>"%%~dpGlist.txt"
来源:https://stackoverflow.com/questions/40225433/batch-files-list-all-files-in-a-directory-print-as-txt-and-place-output-file