Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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 为什么在处理非文本文件时/F通常与FOR循环一起使用?_Batch File_For Loop - Fatal编程技术网

Batch file 为什么在处理非文本文件时/F通常与FOR循环一起使用?

Batch file 为什么在处理非文本文件时/F通常与FOR循环一起使用?,batch-file,for-loop,Batch File,For Loop,我正在寻找一个批处理脚本来识别目录中的最新文件。我发现的示例都用于/F。当我阅读FOR上的帮助文档时,它说明/F打开、读取和处理每个文件 为什么在这种情况下使用/F?我用它来处理大的二进制文件,脚本似乎没有变慢,所以我不认为每个文件都被打开了,等等 我尝试使用FOR without/F做同样的工作,但没有任何运气。这有什么原因吗 例如: FOR %%I IN ('dir "*.AVI" /B /O:D') DO set newestAvi=%%I 似乎不起作用。出于某种原因,newestAv

我正在寻找一个批处理脚本来识别目录中的最新文件。我发现的示例都用于/F。当我阅读FOR上的帮助文档时,它说明/F打开、读取和处理每个文件

为什么在这种情况下使用/F?我用它来处理大的二进制文件,脚本似乎没有变慢,所以我不认为每个文件都被打开了,等等

我尝试使用FOR without/F做同样的工作,但没有任何运气。这有什么原因吗

例如:

FOR %%I IN ('dir "*.AVI" /B /O:D') DO set newestAvi=%%I 
似乎不起作用。出于某种原因,newestAvi最后等于“/O:D”

如果我使用

FOR /F "delims=|" %%I IN ('dir "*.AVI" /B /O:D') DO set newestAvi=%%I
然后事情就开始了

谢谢


Dave

我认为帮助文件的相关部分是

Finally, you can use the FOR /F command to parse the output of a
command.  You do this by making the filenameset between the
parenthesis a back quoted string.  It will be treated as a command
line, which is passed to a child CMD.EXE and the output is captured
into memory and parsed as if it was a file.  So the following
example:
因此,使用/F命令可以从

dir "*.AVI" /B /O:D
并将每一行解析为命令

newestAvi=%%I
变成

newestAvi=FileName.AVI
对于当前目录中的每个文件。最后分配的值是留在命令执行末尾的值