Batch file 无法使用批处理文件生成列表?

Batch file 无法使用批处理文件生成列表?,batch-file,Batch File,我正在尝试使用以下命令获取我电脑上所有父目录的列表,但它不起作用 for %%p in (a b 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 if exist for dir %%p:\nul /ad /b > C:\directorylist.txt 有人能帮忙吗?您有一些错误。在NT版本的Windows中,该\nul不再在所有情况下都正确 @echo off for %%p in (a b c d e f g h i j k

我正在尝试使用以下命令获取我电脑上所有父目录的列表,但它不起作用

for %%p in (a b 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 if exist for dir %%p:\nul /ad /b > C:\directorylist.txt

有人能帮忙吗?

您有一些错误。在NT版本的Windows中,该\nul不再在所有情况下都正确

@echo off
for %%p in (a b 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 if exist  %%p:\ dir /ad /b >> C:\directorylist.txt

当你运行它时会发生什么?我加了一个暂停,看看CMD会返回什么,我得到如下结果:C:\>if-exist dir a:\/ad/b1>directorylist.txthit(尽管我不知道Nul的情况)没有帮助我的CMD一直返回1>directorylist.txt,而我希望出现FOLDERNAME>directorylist.txt之类的情况吗?
1>
是正常的。你的档案里有什么?你确实复制并粘贴了更改后的代码,是吗?是的,我复制并粘贴了它没有生成文件,但我正要重新启动我的电脑。。。我注意到在过去,bat文件有时会卡在内存中,并像没有Eddite一样运行。BRB的回答是:)啊,现在它工作了,我想只是一台电脑坏了,谢谢。请注意,由于访问限制,c:\在现代Windows中不可写。尝试使用以下命令在桌面上创建文件:
>%USERPROFILE%\desktop\directorylist.txt“