尝试使用cmd将所有驱动器中的所有文件夹和子列表都列出到文件中

时间:2015-02-27 23:19:07

标签: cmd

我是新手,请耐心等待。我尝试将所有驱动器中的所有文件夹列入txt文件中的列表。当驱动器搜索到达读卡器驱动器并发现它们为空时,我会收到错误。尝试2> nul无济于事。我的语法偏离了基础吗?感谢

rem ----------list all folders in all drives and copy to a file
for %%a in (c d e f g h i j k l m n o p q u r s t u v w x y z) do (if exist "%%a:\" 2>nul |dir "%%a:\" /ad /b /s >"c:\alldirs.txt")

2 个答案:

答案 0 :(得分:0)

下一个代码应该有效:

echo off
rem ----------list all folders in all drives and copy to a file
(for %%a in (c d e f g h i j k l m n o p q u r s t u v w x y z) do if exist %%a:\ dir %%a:\ /ad /b /s)>"c:\alldirs.txt" 2>nul

或将这条丑陋的线分解成多行:

(for %%a in (c d e f g h i j k l m n o p q u r s t u v w x y z) do (
     if exist %%a:\ (
          dir %%a:\ /ad /b /s
     )))>"c:\alldirs.txt" 2>nul

答案 1 :(得分:0)

我最终使用了vol。这工作

for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do vol %%a: 2>nul |find "Volume" >nul && dir "%%a:\" /ad /b /s >>c:\alldirs.txt