Jump to content

Cannot read file


Recommended Posts

Hi All, I have not visiting you for long time, happy to be here again !!!!

I need help, I have a file that it is fails to opened with _FileReadToArray() function. It returns error 1 ("Error opening specified file").

 

BTW: For general info, the file is created on Amazon S3 and I downloaded it to my windows PC (win 7)

Any other application other then autoit script is opening it properly without any issue.

Not all files from S3 has that problem and this is raise some concern for me that something is wrong with autoit.

Can you please help to investigate it?.

I attached an example such "problematic" file.

 

Here is the code how I call to open the file.

Func _GetTestNameFromResultsFile($ResultsFile)
    Local $i, $arrContent, $arrLine, $res = 0
    Local $delim = ",", $aRet
    $res = _FileReadToArray($ResultsFile, $arrContent)
    If $res = 1 Then ;succes
        For $i = 1 To 1 
            $arrLine = StringSplit($arrContent[$i], $delim)
            If IsArray($arrLine) And $arrLine[0] <> 0 Then
                $aRet = StringSplit($arrLine[1], '/')
                Return $aRet[4]
            Else
                _Log_Report($hLog, "_GetTestNameFromResultsFile: Error splitting first line!", 5)
                SetError(2)
            EndIf
        Next
    Else
        _Log_Report($hLog, "_GetTestNameFromResultsFile: Error opening file for reading test name! " & "error:" & @error, 5)
        SetError(1)
    EndIf
EndFunc   ;==>_GetTestNameFromResultsFile

 

 

 

all_clips_results.csv

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Random guess... are you copying/downloading that file with the same script and accidentally trying to open it whilst it is still being copied and has a file lock on it? Does anything else have write access to it that is causing a file protection event of some kind?

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

I made the small amount of effort required to turn that into a self-contained, running replicator.

#include <File.au3>


Global $sReturnedValue = _GetTestNameFromResultsFile("all_clips_results.csv")
MsgBox(0, "Log", $sReturnedValue)


Func _GetTestNameFromResultsFile($ResultsFile)
    Local $i, $arrContent, $arrLine, $res = 0
    Local $delim = ",", $aRet
    $res = _FileReadToArray($ResultsFile, $arrContent)

    If $res = 1 Then ;success
        For $i = 1 To 1 
            $arrLine = StringSplit($arrContent[$i], $delim)
            If IsArray($arrLine) And $arrLine[0] <> 0 Then
                $aRet = StringSplit($arrLine[1], '/')
                Return $aRet[4]
            Else
                MsgBox(0, "Log", "_GetTestNameFromResultsFile: Error splitting first line!")
                SetError(2)
            EndIf
        Next
    Else
        MsgBox(0, "Log", "_GetTestNameFromResultsFile: Error opening file for reading test name! ")
        SetError(1)
    EndIf
EndFunc   ;==>_GetTestNameFromResultsFile

And using your supplied test data it reads the file and returns some data.

Edited by SlackerAl

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

7 hours ago, SlackerAl said:

Random guess... are you copying/downloading that file with the same script and accidentally trying to open it whilst it is still being copied and has a file lock on it? Does anything else have write access to it that is causing a file protection event of some kind?

 

Thanks

 

Edit: found bug in my code. thanks for the help.

Edited by lsakizada

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...