Batch Files: List all files in a directory, print as .txt and place output file in all sub directories

青春壹個敷衍的年華 提交于 2020-01-21 10:33:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!