我的硬盘上有一个文件夹,里面有大约 1000 个子文件夹。这些子文件夹包含文件,有时还包含更多子文件夹。现在我想要一个脚本,用于创建一个 .txt 文件每个第一级文件夹。这些文件夹包含文件名列表,最后包含子文件夹和子文件的名称。重要的是不要将所有内容塞进一个文件中,而是将其塞进单独的文件中。
它应该看起来像这样
Name of the first folder.txt
Name of the second folder.txt
Name of the third folder.txt
Name of the fourth folder.txt
Name of the fifth folder.txt
Name of the sixth folder.txt
和第一个文件夹的名称.txt应该包含这样的列表
Name of the first file.xyz
Name of the second file.zzz
Name of the third file.xyz
Name of the fourth file.zzz
Name of the fifth file.xyz
Name of Subfolder 1
Name of file.zzz
Name of another file.zzz
Name of Subfolder 2
Name of file.xyz
Name of Subsubfolder 1
Name of file.xyz
Name of file2.zzz
答案1
使用tree
命令打印目录结构的快速解决方案。
@echo off
:: for each directory...
for /d %%D in (*) do (
:: we'll go into it...
cd %%~nxD
:: use the 'tree' command to output its
:: structure in a nice way...
tree /a /f > ..\%%~nxD.txt
:: go back...
cd ..
:: remove the first 3 (useless) lines from the 'tree' output
echo %%~nxD > stackoverflowrules.tmp
for /f "skip=3 delims=*" %%a in (%%~nxD.txt) do (
echo.%%a >> stackoverflowrules.tmp
)
copy /y stackoverflowrules.tmp %%~nxD.txt
del /f /q stackoverflowrules.tmp
)