Jump to content

Recommended Posts

Posted

Hello, I've got a file open error: Unable to open file. I am administrator of box so it's not a privilege issue. Any ideas? Thanks.

$file = FileOpen("test.txt", 0)

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

FileClose($file)
Posted

I've tried that already, no good:

$file = FileOpen("C:\docume~1\olvermo\Desktop\test.txt", 0)

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

FileClose($file)
Posted (edited)

I would try something like:

If FileExists(@DesktopDir & "\text.txt") Then
    $file = FileOpen(@DesktopDir & "\test.txt", 0)
    
; Check if file opened for reading OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    
    FileClose($file)
Else
    MsgBox(0, "Error", "File not found")
EndIf
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

ok, I can use your code and then write to the file:

If FileExists(@DesktopDir & "\text.txt") Then
    $file = FileOpen(@DesktopDir & "\text.txt", 1)
    filewrite($file,"hello there")
    
; Check if file opened for reading OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    
    FileClose($file)
Else
    MsgBox(0, "Error", "File not found")
EndIf

however, I want to be able to create the file if it doesn't exist....I figured it out. Thanks for your help!

If NOT FileExists(@DesktopDir & "\text.txt") Then

$file = FileOpen(@DesktopDir & "\text.txt", 1)

filewrite($file,"hello there")

FileClose($file)

endif

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
×
×
  • Create New...