我在使用“for/f”时遇到一些困难,无法找到具有特定名称的文件。当文件或路径包含空格时,此站点上的许多用户都会遇到此问题,但这里并非如此。简单示例,名为“test4.cmd”的批处理文件:
@echo off
set ln=%1
if exist 2013_10_23_Cal_Curve.txt echo The first file exists.
if exist ~temp1.txt echo The second file exists.
for /f "skip=%ln% tokens=2" %%a in (2013_10_23_Cal_Curve.txt) do echo Found the first file.
for /f "skip=%ln% tokens=2" %%a in (~temp1.txt) do echo Found the second file.
输出:
C:\Users\wnc7\Desktop\jmp_test_data>test4 1 The first file exists. The second file exists. The system cannot find the file 2013_10_23_Cal_Curve.txt. Found the second file. Found the second file. Found the second file. *(expected output continues for second file....)*
其他命令如findstr可以找到文件,但是for/f找不到。而for/f 可以在同一目录下找到以相同格式编写的~temp1.txt。
我试过“usebackq”并将文件名放在引号中,但无济于事。感谢您的帮助。
迈克
最佳答案
文件被另一个进程阻止读取。如果不能读取,则存在,可以找到,但for/f
无法处理。而不是 for 命令,尝试 type file
或 delete file
,然后错误将是系统无法访问该文件,因为它正在被另一个进程使用。
关于windows - for/f "the system cannot find the file"在 windows 命令脚本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19728704/