2013-11-01 25 views
1

我遇到了一些困難,「for/f」無法找到具有特定名稱的文件。當文件或路徑包含空格時,此站點上的許多用戶都遇到了這個問題,但這裏並不是這種情況。簡單的例子,一個名爲 「test4.cmd」 批處理文件:for/f「系統無法找到文件」在Windows命令腳本中

@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可以找到該文件,但對於/ f不能找到它。然而,/ f可以找到〜temp1.txt以相同的格式寫在同一個目錄中。

我試過「usebackq」並將文件名放在引號中,無濟於事。任何幫助表示讚賞。

Mike

+0

只顯示'2013_10_23_Cal_Curve.txt'的內容。 – Endoro

回答

2

該文件被另一個進程讀取阻塞。如果無法獲得,它就存在,並且可以找到,但for /f無法處理它。而不是命令,請嘗試type filedelete file,那麼錯誤將是系統無法訪問該文件,因爲它正在被另一個進程使用。

+1

這是問題所在。第一個文件被另一個程序鎖定,我沒有意識到。錯誤信息有點欺騙性,不是嗎?非常感謝你的幫助,因爲它讓我瘋狂! – user2945218

相關問題