BrewManNH Posted March 29, 2012 Posted March 29, 2012 Try this version: expandcollapse popup#include <File.au3> ; Open the text file and read it ready for writing. ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file) Local $answer = MsgBox(4, "SPF-Editor", "Warning all SPF's in the .exe's directory will change, ok?") ; Check the user's answer to the prompt (see the help file for MsgBox return values) ; If "No" was clicked (7) then exit the script If $answer = 7 Then Exit MsgBox(0, "SPF-Editor", "Buh Bye!") EndIf MsgBox(0, "Running", "The program will prompt you when it has finished!") Local $filer = FileOpen("text.txt", 0) ; Check if file opened for reading OK If $filer = -1 Then MsgBox(0, "Error", "Unable to open file!!") Exit EndIf ; Start finding files for writing. ; Shows the filenames of all files in the current directory Local $search = FileFindFirstFile("*.spf*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "Eeeeeroar!!") Exit EndIf Global $Text = "3" & @CRLF, $Array Local $line = FileRead($filer) ; reads the entire file at one time $Text &= $line ; adds the file to the $Text variable which contains the number 3 and a line feed FileClose($filer) While 1 Local $file = FileFindNextFile($search) If @error Then ExitLoop $Temp = FileOpen($file) ; Opens the file for read $read = FileRead($Temp) ; reads the file into $read FileClose($Temp) ; close the file $read = StringReplace($read, "-1", $Text) ; replace the text -1 with the contents of $Text $Temp = FileOpen($file, 2) ; reopens the file, but deletes the contents of it FileWrite($Temp, $read); write $read to $File FileClose($Temp) ; close the file handle WEnd MsgBox(0, "Done", "The script has stopped and your files are edited!") ; Close the search handle mofo FileClose($search) If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
kylomas Posted March 29, 2012 Posted March 29, 2012 (edited) gazeranco,Did you try BrewmanNH's solution using [color="#5a5a5a"]$Array[/color][[color="#5a5a5a"]$Array[/color][0] - 2] = [color="#5a5a5a"]$TextkylomasEdit: Don't have any idea why the editor freaked out. The line of code I am trying to cite is "$Array[$Array[0] - 1] = $Text" Try changing it to "-2". Edited March 29, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
kylomas Posted March 29, 2012 Posted March 29, 2012 gazeranco, Can you post an example of the files that you are working with? The solutions posted by both BrewmanNH and I work against simple text type test files that I created on my PC. However, our solutions assume that lines are delimited by rn and do NOT remove blank lines at the end of the file. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
gazeranco Posted March 29, 2012 Author Posted March 29, 2012 Brewman. That last one appears to work perfectly. Thanks!! Now i will read and try and understand it all.
gazeranco Posted March 29, 2012 Author Posted March 29, 2012 Ahhh no. That replaces every instance of -1. -1 appears alot throughout the files not jyst at the end.
kylomas Posted March 29, 2012 Posted March 29, 2012 gazeranco, Yes, I thought that might be a problem...can you give an example of the files that you are working with? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
BrewManNH Posted March 29, 2012 Posted March 29, 2012 the last line in a .spf is "-1" this represents the end of fileObviously this part isn't right if the -1 doesn't mark the end of the file. If there are more than one -1 in the file, this can't indicate anything to the program reading it that deals with EOF. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
kylomas Posted March 29, 2012 Posted March 29, 2012 @brewmanNH, This "-1" crap is a defacto, albeit pervasive practice...we need an example of the files that he is working with. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
gazeranco Posted March 30, 2012 Author Posted March 30, 2012 Theres a part example in readme.txt in the files on page 1. I see what your saying but the spf always ends with a minus 1, despite it existing throughout the spf file.
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