Jump to content

File Opening


Ace08
 Share

Recommended Posts

guys another quick question here, when i a FileOpen($FileName) does the script realy opens the file or does the script saves the contents in a memory? because what i would like to do is change a certain line in a file then just append the other lines?

Work smarter not harder.My First Posted Script: DataBase

Link to comment
Share on other sites

It creates a handle, or link, to the file. Windows will then consider the file open, or in-use, until the handle is closed. None of the data in the file is read into memory with FileOpen().

Sounds like you might just want to do a _FileReadToArray(), then modify whatever line(s) you want, then do a _FileWriteFromArray(). There are examples for those commands in the helpfile .

Link to comment
Share on other sites

guys another quick question here, when i a FileOpen($FileName) does the script realy opens the file or does the script saves the contents in a memory? because what i would like to do is change a certain line in a file then just append the other lines?

Just like what Spiff59 has said, FileOpen does nothing to the file content. What it does is creates a "handle". Here are some examples:

1. Read, Change, Save

; read data
$data = FileRead("xxx.txt"); you can use FileOpen, if you want to.
;~ $file = FileOpen("xxx.txt",0)
;~ $data = FileRead($file)
;~ FileClose($file)

$data = StringReplace($data,"b",""); Replace 'b' with empty string a.k.a delete char 'b'

;open file in erase previos data mode
$file = FileOpen("xxx.txt",2)
FileWrite($file,$data)
FileClose($file)

xxx.txt, before

aaa

bbb

ccc

xxx.txt, after

aaa

ccc

2. Save, append to end of file

$file = FileOpen("xxx.txt",1)
FileWrite($file,"ddd")
FileClose($file)

or simply

FileWrite("xxx.txt","ddd")

"xxx.txt" - before

aaa

bbb

ccc

"xxx.txt" - after

aaa

bbb

cccddd

Hi ;)

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