Jump to content

Doubt in FileOpen


XORGate
 Share

Recommended Posts

A few days ago, i got introduced to AutoIt and i've already started working on my project and frankly, I have negligible experience in VB. (I don't know why but AutoIt looks a lot like VB to me)

So i've bee dropping off on tutorials, reading the libraries and everything and i got stuck in this FileOpen(). How? Here's a piece of code that i copied from the example given in the www.autoitscripts.com lib

$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)

; Another sample which automatically creates the directory structure
$file = FileOpen("test.txt", 10) ; which is similar to 2 + 8 (erase + create dir)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
FileClose($file)

Now the problem is, when i ran this code, Nothing happened. I even tried to create a test.txt in directory where i have saved this script but still nothing desirable happened. Instead, what happened was that my test.txt's size became 0kb after the script completed it's execution. What i basically want to do is:

Read specific end lines of a file in notepad and then copy it in another. (Please don't misunderstand me, i'm not asking u guys to make the code for me! :mellow:) So i guess opening the file is the first step.

Please tell me what's wrong.. What should i do?!

Link to comment
Share on other sites

There's nothing wrong, FileOpen() with mode 2 is supposed to erase the file, see helpfile

2 = Write mode (erase previous contents)

Also, while you are there look at the Related-section. Could FileRead() be what you want? :mellow:

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