windows - for/f "the system cannot find the file"在 windows 命令脚本中

标签 windows batch-file cmd

我在使用“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 filedelete file,然后错误将是系统无法访问该文件,因为它正在被另一个进程使用。

关于windows - for/f "the system cannot find the file"在 windows 命令脚本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19728704/

相关文章:

java - CMD:如何将 java -version 的结果写入/打印到某个文件

batch-file - 从FTP服务器下载最新文件的批处理文件

powershell - 从 cmd 运行 PowerShell 方法,不要等待它的返回

python - 如何在 Windows 上从 python 获取长文件系统路径

windows - 如何将低级命令(非 APDU)发送到 Windows 10(移动)上的智能卡?

c++ - 如何在 Visual Studio 2015 中更改默认的新项目打开 C++ 代码?

windows - 使用标准用户帐户在提升的脚本中获取登录用户名

batch-file - 从批处理文件中找到已安装程序的版本

asp.net - dotnet 构建中当前目录中的错误 : 'Couldn' t find project. json

bash - Windows 10 原生 bash 确实响应 VSCode 中的 tasks.json