Jump to content

Open error


Recommended Posts

Hi,

The following code is contained within a script. The error message is being triggered upon execution because the file cannot be opened/read. That should not be the case. Is there an obvious error with this? It should "Close" the file even after the error is thrown, correct?

;write to the "source" file (erase)

$source = FileOpen("C:\Documents and Settings\My Documents\1517.txt", 10)

;Check if file opened for reading OK

If $source = -1 Then

MsgBox(0, "Error", "Unable to open 1517 file.")

Exit

EndIf

FileWriteLine($source, $PASS & " " & $AsDIFF & " " & $AgDIFF & " ")

FileClose($source)

Link to comment
Share on other sites

test ok...

Autoit 3.2.12.0

Win Xp sp2

;write to the "source" file (erase)
$source = FileOpen("C:\15177.txt", 10)
;$source = FileOpen("C:\Documents and Settings\My Documents\1517.txt", 10)

;Check if file opened for reading OK
If $source = -1 Then
    MsgBox(0, "Error", "Unable to open 1517 file.")
    Exit
EndIf

FileWriteLine($source, "test") ;$PASS & " " & $AsDIFF & " " & $AgDIFF & " ")

FileClose($source)

ShellExecute("C:\15177.txt")

8)

NEWHeader1.png

Link to comment
Share on other sites

Hi,

The following code is contained within a script. The error message is being triggered upon execution because the file cannot be opened/read. That should not be the case. Is there an obvious error with this? It should "Close" the file even after the error is thrown, correct?

;write to the "source" file (erase)

$source = FileOpen("C:\Documents and Settings\My Documents\1517.txt", 10)

;Check if file opened for reading OK

If $source = -1 Then

MsgBox(0, "Error", "Unable to open 1517 file.")

Exit

EndIf

FileWriteLine($source, $PASS & " " & $AsDIFF & " " & $AgDIFF & " ")

FileClose($source)

There is usually a @UserName within that path. "My Documents" would not be directly under "Documents and Settings". You might try forming a path like:
$sFile = @MyDocumentsDir & "\1517.txt"
$hFile = FileOpen($sFile, 10); Overwrite, create path
If $source = -1 Then
      MsgBox(0, "Error", "Unable to open 1517 file.")
Else
    FileWriteLine($source, $PASS & " " & $AsDIFF & " " & $AgDIFF & " ") 
EndIf   

FileClose($source)

If that is not the problem, why do you say "That should not be the case"? Can you delete/create that file in that location from the command line?

If the file is not opened, then there is nothing to close, but your script won't execute FileClose() after the error because of the "Exit" right after the MsgBox().

Upon Exit, AutoIt automatically closes all open files/handles.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks for the response. I say "that should not be the case" because the file exists. I can open/close/edit it manually without any issue. Is there a way to somehow determine why the error is occuring/why the file cannot be opened? Thanks for the info about the "Exit", I wasn't aware handles would be automatically manipulated like that.

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...