Jump to content

"Unable to Open File" ?


Recommended Posts

All I'm trying to do is read from a text file. & Display in a message Box. But Every time I run it, All I get is "Unable to Open File". Any Ideas?

Here's the Code (just the basic one from the examples) :

#include <file.au3>

$file = FileOpen(@ScriptDir & "\Generics.txt", 0)

$line = FileRead($file)

MsgBox(0,'',$line)
FileClose($file)

What am I Missing?

Link to comment
Share on other sites

Nothing in the code you posted requires the File.au3 UDF to be included. It isn't hurting anything, just not helping.

Either Generics.txt is not in the script directory, or you don't have read permissions to it.

Throw in some error handling:

$sFile = @ScriptDir & "\Generics.txt"
If FileExists($sFile) Then
    $hFile = FileOpen($sFile, 0)
    If $hFile = -1 Then
        MsgBox(16, "Error", "Failed to open file for read:  " & $sFile)
    Else
        $sData = FileRead($hFile) ; Reads the whole file
        MsgBox(64, "Data", $sData)
        FileClose($hFile)
    EndIf
Else
    MsgBox(16, "Error", "File doesn't exist:  " & $sFile)
EndIf

:(

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

Nothing in the code you posted requires the File.au3 UDF to be included. It isn't hurting anything, just not helping.

Either Generics.txt is not in the script directory, or you don't have read permissions to it.

Throw in some error handling:

$sFile = @ScriptDir & "\Generics.txt"
If FileExists($sFile) Then
    $hFile = FileOpen($sFile, 0)
    If $hFile = -1 Then
        MsgBox(16, "Error", "Failed to open file for read:  " & $sFile)
    Else
        $sData = FileRead($hFile) ; Reads the whole file
        MsgBox(64, "Data", $sData)
        FileClose($hFile)
    EndIf
Else
    MsgBox(16, "Error", "File doesn't exist:  " & $sFile)
EndIf

:(

Oh, That was Really Helpful! It says it doesn't exist. But it really Does... So Permissions, but its Windows how do you change permissions, do they have permissions?

Link to comment
Share on other sites

It may affect your permissions in certain OS' depending on where your script is.

Try replacing #include <file.au3> with #RequireAdmin

Thanks, but That didn't work. Without it doesn't work. Its Version 3.3.6.0 AutoIt. WinXP Home Version. any other Ideas?

Link to comment
Share on other sites

Sorry, but everything here points to the file not being there, by either a spelling mistake or an incorrect path.

Try moving the target file to another location such as @DocumentsCommonDir and trying to open it there.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hi,

you may try (Generics.txt is really in same directory as your AutoIt Script?):

$file = @ScriptDir & "\Generics.txt"
If FileExists ($file) Then
    $line = FileRead($file)
    MsgBox(0,'',$line)
Else
    MsgBox (0,"Error", "File not in " & @ScriptDir)
EndIf

;-))

Stefan

P.S to check security settings:

1) Run explorer and do a right mouse click on generics.txt -> Properties -> security tab

or

2) Run cmd.exe -> cacls <Fullpath to Generics.txt> and see output

Link to comment
Share on other sites

Hi,

you may try (Generics.txt is really in same directory as your AutoIt Script?):

$file = @ScriptDir & "\Generics.txt"
If FileExists ($file) Then
    $line = FileRead($file)
    MsgBox(0,'',$line)
Else
    MsgBox (0,"Error", "File not in " & @ScriptDir)
EndIf

;-))

Stefan

P.S to check security settings:

1) Run explorer and do a right mouse click on generics.txt -> Properties -> security tab

or

2) Run cmd.exe -> cacls <Fullpath to Generics.txt> and see output

AH! Thank You! Thank You, that one did it. Turns out for some reason it had a double extension. Not shown in any view except from the cmdline. Finally it works, YAY!

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