Jump to content

Need help with file save


Recommended Posts

I am trying to create file (Save as button on my guy)

and i want save new file and create it only with some lines.its hard to describe it.I am trying to explain...

When i made save button that simply overwritten lines in old file then it worked that way.Then I added save as button that must create new file,I creates new file but my problem is that my script wont write any lines on that new file that made with save as button from gui.

1st I tried:

_FileCreate($filename&".lua"); I didnt have that with save button.I added this for save as button

$IsSelected = GUICtrlRead ($orb); == > $orb is check box

If $IsSelected = 1 Then $IsSelected = 'loadfile(dir .. "other\\orb.lua")()' ; == > If check box is selected then write this line

If $IsSelected = 4 Then $IsSelected = '--loadfile(dir .. "other\\orb.lua")() ; == > If check box is not selected then write this line

_FileWriteToLine($filename&".lua",55,$IsSelected,0) ; == > ok here I am trying to write 55 th line for file, but this script creates new empty file but it dont write any text on 55 th line

How i can write that 55 th line when i tell script to make new file?

I need write specific line in new freshly created file.

Link to comment
Share on other sites

I tried make it more simple. so how i can make it write lines int that file?

#include <File.au3>
;Example: Write to line 3 of c:\test.txt REPLACING line 3
_FileCreate("c:\test.txt")
_FileWriteToLine("c:\test.txt", 3, "my replacement for line 3", 1)
;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3
_FileWriteToLine("c:\test.txt", 3, "my insertion", 0)
Link to comment
Share on other sites

I'm not sure you can replace a line that doesn't exist, so you should create line 3 first:

#include <File.au3>
$file = "c:\test.txt"
$file_open = FileOpen($file, 1)
for $i = 1 to 2
    FileWriteLine($file_open, $i); you can make "" instead of $i, to make the lines blank.
Next
FileClose($file_open)
MsgBox(0, $file, "the specified file now counts 3 lines," & @CRLF & "press OK to rename line 3")
_FileWriteToLine($file, 3, "my replacement for line 3", 1)
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...