Sign in to follow this  
Followers 0
Ace08

File Opening

4 posts in this topic

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

Share this post


Link to post
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 .

Share this post


Link to post
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 ;)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks a lot guys for the info :)

Oh and one more thing is there a way to edit the contents in a GUIListView?

;) got this one Thanks ;)

Edited by Ace08

Work smarter not harder.My First Posted Script: DataBase

Share this post


Link to post
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
Sign in to follow this  
Followers 0