Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 自动化.bat以获取给定目录的所有内容_Batch File_Filelist - Fatal编程技术网

Batch file 自动化.bat以获取给定目录的所有内容

Batch file 自动化.bat以获取给定目录的所有内容,batch-file,filelist,Batch File,Filelist,我正在尝试将所有内容(目录、子目录、文件等)存储在.txt文件中的过程自动化。我想到了这个: cd "D:\sources\SVN_WorkingCopy\" dir /s /b>filelist.txt 将上述内容放入.bat文件并手动运行时,它工作正常并创建.txt文件。但是,当我将它包含在Windows计划任务中时,它什么也不做。有人能帮忙吗,让它工作起来 谢谢 如果您真的想在两行中完成,那么您需要确保使用/D选项来更改驱动器: CD/D“D:\sources\SVN\u Work

我正在尝试将所有内容(目录、子目录、文件等)存储在.txt文件中的过程自动化。我想到了这个:

cd "D:\sources\SVN_WorkingCopy\"
dir /s /b>filelist.txt
将上述内容放入.bat文件并手动运行时,它工作正常并创建.txt文件。但是,当我将它包含在Windows计划任务中时,它什么也不做。有人能帮忙吗,让它工作起来


谢谢

如果您真的想在两行中完成,那么您需要确保使用
/D
选项来更改驱动器:

CD/D“D:\sources\SVN\u WorkingCopy”
目录/S/B>“filelist.txt”
或者,您可以在不更改当前工作目录的情况下使用单行:

Dir/S/B“D:\sources\SVN\u WorkingCopy”>“filelist.txt”
或者使用不同的命令:

Where/R“D:\sources\SVN\u WorkingCopy”*>“filelist.txt”
此外,您还需要注意,当作为计划任务运行时,工作目录是
%SystemRoot%\System32
,默认情况下,该目录受写保护(取决于权限)。因此,除非您提供可访问的位置,否则该命令将尝试将其输出发送到该文件:

“C:\Users\kalinkula\Desktop\filelist.txt”
您可以将输出发送到评估目录中的文件,
D:\sources\SVN\u WorkingCopy\filelist.txt
,只要您不介意该文件出现在它自己包含的列表中


这些答案还假设
D:
在脚本/命令运行时已映射和/或可用。

这可能只是供参考的,但您也可以使用
树进行结构化输出

tree /f /a "D:\sources\SVN_WorkingCopy" > filelist.txt
这将导致文件结构类似于:

D:.
├───e-shopper
│   └───Eshopper
|       └───temp folder
|           └───Performance Report Table.xlsx
|           └───Sales Document.docx
├───test Folder
│   └───Hire Freelancers
|       └───Performance Report Table.xlsx
|       └───Sales Document.docx
└───Some other Directory with no subs or files

cd/d“d:…
应该可以。谢谢!这样做了。