emendelson Posted May 25, 2006 Share Posted May 25, 2006 My script needs to write new first lines to various different text files (in each case, the line contains a variable that will be used in a batch file or similar file). I use a kludge to accomplish this, and I wonder if there is an easier way. The kludge looks like this: it FileInstalls a temporary file with all of the text in the eventual text file EXCEPT the first line, then creates another temporary file that contains only the first line of the eventual text file - built from variables - and then uses the COPY command to combine the newly-created temporary file and the FileInstalled temporary file into the file I want to leave on disk. FileInstall("c:\TestFiles\template.tmp", $mypath, 1) $handle1 = FileOpen($mypath & "empty.tmp", 2) FileWriteLine($handle1, "set somevariable =" & Chr(34) & $variabletext & Chr(34)) FileClose($handle1) RunWait(@ComSpec & " /c " & 'copy empty.tmp + template.tmp target.cmd', $mypath, @SW_HIDE) It works, but is there an all-AutoIt way to do this that doesn't require @ComSpec and would be more elegant? Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted May 25, 2006 Moderators Share Posted May 25, 2006 (edited) My script needs to write new first lines to various different text files (in each case, the line contains a variable that will be used in a batch file or similar file). I use a kludge to accomplish this, and I wonder if there is an easier way. The kludge looks like this: it FileInstalls a temporary file with all of the text in the eventual text file EXCEPT the first line, then creates another temporary file that contains only the first line of the eventual text file - built from variables - and then uses the COPY command to combine the newly-created temporary file and the FileInstalled temporary file into the file I want to leave on disk. FileInstall("c:\TestFiles\template.tmp", $mypath, 1) $handle1 = FileOpen($mypath & "empty.tmp", 2) FileWriteLine($handle1, "set somevariable =" & Chr(34) & $variabletext & Chr(34)) FileClose($handle1) RunWait(@ComSpec & " /c " & 'copy empty.tmp + template.tmp target.cmd', $mypath, @SW_HIDE) It works, but is there an all-AutoIt way to do this that doesn't require @ComSpec and would be more elegant?As long as your using the beta version you could use: _FileWriteToLine($handle1, 1, "set somevariable =" & Chr(34) & $variabletext & Chr(34), 0) Edited May 25, 2006 by big_daddy Link to comment Share on other sites More sharing options...
BigDod Posted May 25, 2006 Share Posted May 25, 2006 (edited) Would it not be easier to use _FileWriteToLine to write to line 1 of the file with the overwrite option set to 0 Edit - Oops too slow again Edited May 25, 2006 by BigDod Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
emendelson Posted May 25, 2006 Author Share Posted May 25, 2006 Would it not be easier to use _FileWriteToLine to write to line 1 of the file with the overwrite option set to 0Edit - Oops too slow againExactly what I needed; thank you.! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now