2014-03-01 56 views
1

我寫了一個簡單的腳本,它將從包含文件位置的文本文件逐行讀取,然後檢查文件是否存在。由於某些原因,即使文件存在,FileExists函數也會始終返回0。這是我的代碼部分:FileExists函數在AutoIt的'for'循環中不起作用

$iFileLines=_FileCountLines($sFilePath) 
For $iLineNumber=1 To $iFileLines  
    Local $sTmpLine=FileReadLine($sFilePath, $iLineNumber) 
    If FileExists($sTmpLine) Then 
      ;do something 
    Else 
      ;do something 
    EndIf 
Next 

只是爲了澄清,在哪個腳本讀取文本文件的形式每一道線條都是我的電腦上的文件,寫成了「位置」的方式的位置,以及閱讀地點工作正常。

我在做什麼錯?

回答

1

您已經$ sFilePath

通行證FILEEXISTS INSEAD $ sFilePathFileExists通過$ sTmpLine,並檢查它

2

更好地利用_FileReadToArray。

#include <File.au3> 

Local $aRecords 

If Not _FileReadToArray($sFilePath, $aRecords) Then 
    MsgBox(4096, "Error", " Error reading File to to Array  error:" & @error) 
    Exit 
EndIf 

For $x = 1 To $aRecords[0] 

    If FileExists($aRecords[$x]) Then 
      ;do something 
    Else 
      ;do something 
    EndIf 

Next 
0

只是刪除了「」(引號)圍繞由腳本讀取裏面的文件寫入的文件位置路徑(在$sFilePath),它會工作。