Jump to content

Saving text to another .au3 file and replace if it already excist

Recommended Posts

So Im trying to start shortcuts with proxy and want to save the file output as a variable like 

$client1 = "C:/shortcut.lnk"

what I tried is saving it with iniwrite but then I get a [] in the file wich makes the script return to an error.

I also tried :

Func Save()
If _GUICtrlEdit_GetLine($Edit1, 0) = True Then
$FileName = GUICtrlRead($Input1)
;$FileName = @Systemdir & "\mstsc.exe" ; to work with autoit variables
$args = '_GUICtrlEdit_GetLine($Edit1, 0)
$LinkFileName = GUICtrlRead($Input2) & "\Client1.lnk"
$WorkingDirectory = "%windir%" 
;$WorkingDirectory = @WindowsDir 
$Icon = GUICtrlRead($Input1)
;$Icon = @WindowsDir & \system32\SHELL32.dll"
$IconNumber = 67
$Description = "Concept Icon"

FileCreateShortcut($FileName, $LinkFileName, $WorkingDirectory, $args, $Description, $Icon,"", $IconNumber, $State)
_FileWriteToLine( "Config.au3", 3, "$client1=" & GUICtrlRead($Input2), & '\Client1.lnk"' 1)

But if the .au3 file is empty it will not write in it.

I also tried Filewrite but then It does not replace anything and just add multiple lines with the same variable.

I hope someone can help me out,


Link to comment
Share on other sites

I am trying to get rid of the "[" and "]" in the config file and tried this but still no luck.

can anyone help me out?


$sData = "["

$FileName = "test.txt"
$hFile = FileOpen($FileName, 2)
FileWrite($hFile, $sData)

$hFileOpen = FileOpen($FileName)
$ReadData = FileRead($hFileOpen)
$sNewFile = StringRegExpReplace($ReadData, '[', '')
$sNewFile = StringRegExpReplace($sNewFile, "]", "")

$hFileOpen = FileOpen($FileName, 2)
FileWrite($hFileOpen, $sNewFile)

Link to comment
Share on other sites

FileWrite appends to an existing file. The function description says:


Write text/data to the end of a previously opened file.

To modify an existing file you should delete the original with FileDelete before FileWrite-ing the changed contents back.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...