Jump to content

Recommended Posts

Posted

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?

Posted

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
Posted

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?

Posted

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?

Posted

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

Posted

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!

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
  • Recently Browsing   0 members

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