AmphetaMarinE Posted May 3, 2007 Posted May 3, 2007 Hi guys, I am trying to make a simple script which will automate the creation of an email signature. In order to do this i am trying to use _ReplaceStringInFile in order to replace 3 fields in the signature with information retrieved through an input box. I can get info into my variables ok, but when I try to replace the text, the script erases all data currently in the text file, leaving me with a completely empty file named MyBusiness.txt. Can anyone shed some light on this?? My Code: #include <File.au3> ; Declaring Variables $textsig = 'MyBusiness.txt' $htmlsig = 'MyBusiness.htm' $rtfsig = 'MyBusiness.rtf' ; Get the details we want written to the file $name = InputBox("Full Name", "Please type your Name.", "", " M") $title = InputBox("Job Title", "Please type your Job Title.", "", " M") $email = InputBox("Email", "Please type your full email address.", "", " M") ; Replace the text in the file with our details collected previous. _ReplaceStringInFile ( $textsig, '**name**', $name ) _ReplaceStringInFile ( $textsig, '**title**', $title ) _ReplaceStringInFile ( $textsig, '**email**', $email ) The file I am trying to replace text in (MyBusiness.txt): Regards, **name** **title** http://www.mybusiness.com.au Phone: (07) 12345678 Fax: (07) 12345678 Email: **email** MyBusiness 1234 john st MyCity, State, 1111 THIS EMAIL AND THE INFORMATION THAT IT CONTAINS MAY BE CONFIDENTIAL, LEGALLY PRIVILEGED AND PROTECTED BY LAW. ACCESS BY THE INTENDED RECIPIENT ONLY IS AUTHORISED. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose or store or copy the information within onto any medium. Please delete this email if received in error.
November Posted May 3, 2007 Posted May 3, 2007 Hi... Here it goes! ReplaceStringInFile ( $szFileName, $szSearchString, $szReplaceString, $fCaseness = 0, $fOccurance = 1 ) Parameters $szFileName name of the file to open. ATTENTION !! Needs the FULL path, not just the name returned by eg. FileFindNextFile $szSearchString The string we want to replace in the file $szReplaceString The string we want as a replacement for $szSearchString $fCaseness 0 = Not Case sensitive (default), 1 = Case sensitive, case does matter $fOccurance 0 = Only first found is replaced, 1 = ALL occurrences are replaced (default) So use full path name in your file location. Cheers Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font]
AmphetaMarinE Posted May 3, 2007 Author Posted May 3, 2007 (edited) Hi... Here it goes! ReplaceStringInFile ( $szFileName, $szSearchString, $szReplaceString, $fCaseness = 0, $fOccurance = 1 ) Parameters $szFileName name of the file to open. ATTENTION !! Needs the FULL path, not just the name returned by eg. FileFindNextFile $szSearchString The string we want to replace in the file $szReplaceString The string we want as a replacement for $szSearchString $fCaseness 0 = Not Case sensitive (default), 1 = Case sensitive, case does matter $fOccurance 0 = Only first found is replaced, 1 = ALL occurrences are replaced (default) So use full path name in your file location. Cheers Thanks for your reply november. I have hard coded the full path to my text file, and now I don't get an empty file, but instead of the results I would expect, I get this as my resulting text file (all on one line): 0x52006500670061007200640073002C000D000A002A002A006E0061006D0065002A002A0020000D000A002A002A00740069 0074006C0065002A002A000D000A0068007400740070003A002F002F007700770077002E0061006300650063006F006D0070 00750074006500720077006F0072006C0064002E0063006F006D002E006100750020000D000A000D000A00500068006F006E 0065003A0020002800300037002900200033003800310032002000330039003000300020000D000A004600610078003A0020 00200020002800300037002900200033003800310032002000300035003300330020000D000A0045006D00610069006C003A 0020002A002A0065006D00610069006C002A002A0020000D000A000D000A00410063006500200043006F006D007000750074 0065007200200057006F0072006C00640020000D000A003700350020004200720069007300620061006E0065002000730074 0020000D000A0049007000730077006900630068002C00200051004C004400200034003300300035000D000A000D000A0054 00480049005300200045004D00410049004C00200041004E0044002000540048004500200049004E0046004F0052004D0041 00540049004F004E0020005400480041005400200049005400200043004F004E005400410049004E00530020004D00410059 00200042004500200043004F004E0046004900440045004E005400490041004C002C0020004C004500470041004C004C0059 002000500052004900560049004C004500470045004400200041004E0044002000500052004F005400450043005400450044 0020004200590020004C00410057002E0020004100430043004500530053002000420059002000540048004500200049004E 00540045004E00440045004400200052004500430049005000490045004E00540020004F004E004C00590020004900530020 0041005500540048004F00520049005300450044002E0020000D000A0049006600200079006F007500200061007200650020 006E006F0074002000740068006500200069006E00740065006E00640065006400200072006500630069007000690065006E 0074002C00200070006C00650061007300650020006E006F00740069006600790020007400680065002000730065006E0064 0065007200200069006D006D006500640069006100740065006C007900200061006E006400200064006F0020006E006F0074 00200064006900730063006C006F00730065002000740068006500200063006F006E00740065006E0074007300200074006F 00200061006E00790020006F007400680065007200200070006500720073006F006E002C0020007500730065002000690074 00200066006F007200200061006E007900200070007500720070006F007300650020006F0072002000730074006F00720065 0020006F007200200063006F00700079002000740068006500200069006E0066006F0072006D006100740069006F006E0020 00770069007400680069006E0020006F006E0074006F00200061006E00790020006D0065006400690075006D002E00200050 006C0065006100730065002000640065006C0065007400650020007400680069007300200065006D00610069006C00200069 006600200072006500630065006900760065006400200069006E0020006500720072006F0072002E000D000A000D000A00 Edited May 3, 2007 by AmphetaMarinE
November Posted May 3, 2007 Posted May 3, 2007 Hi AmphetaMarinE, I used your program and runs smooth with me! #include <File.au3> ; Declaring Variables $textsig = 'c:\temp\MyBusiness.txt' $htmlsig = 'c:\temp\MyBusiness.htm' $rtfsig = 'c:\temp\MyBusiness.rtf' ; Get the details we want written to the file $name = InputBox("Full Name", "Please type your Name.", "", " M") $title = InputBox("Job Title", "Please type your Job Title.", "", " M") $email = InputBox("Email", "Please type your full email address.", "", " M") ; Replace the text in the file with our details collected previous. _ReplaceStringInFile ( $textsig, '**name**', $name ) _ReplaceStringInFile ( $textsig, '**title**', $title ) _ReplaceStringInFile ( $textsig, '**email**', $email ) Check your autoit version! Work like a charm: Regards, Pedro Mr. http://www.mybusiness.com.au Phone: (07) 12345678 Fax: (07) 12345678 Email: november@tassebem.com MyBusiness 1234 john st MyCity, State, 1111 So double check your autoit. Cheers Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font]
AmphetaMarinE Posted May 3, 2007 Author Posted May 3, 2007 Odd that it works for you, I just cannot get anything more after the last post.I have the latest production version (v3.2.2.0) installed.I just tried installing the latest beta as well. (v3.2.3.12beta)With v3.2.2.0 I am left with an empty text file.With v3.2.3.12beta I am left with a text file with this content:0x52006500670061007200640073002C000D000A002A002A006E0061006D0065002A002A0020000D000A002A002A007400690074006C0065002A002A000D000A0068007400740070003A002F002F007700770077002E0061006300650063006F006D007000750074006500720077006F0072006C0064002E0063006F006D002E006100750020000D000A000D000A00500068006F006E0065003A0020002800300037002900200033003800310032002000330039003000300020000D000A004600610078003A002000200020002800300037002900200033003800310032002000300035003300330020000D000A0045006D00610069006C003A0020002A002A0065006D00610069006C002A002A0020000D000A000D000A00410063006500200043006F006D0070007500740065007200200057006F0072006C00640020000D000A003700350020004200720069007300620061006E00650020007300740020000D000A0049007000730077006900630068002C00200051004C004400200034003300300035000D000A000D000A005400480049005300200045004D00410049004C00200041004E0044002000540048004500200049004E0046004F0052004D004100540049004F004E0020005400480041005400200049005400200043004F004E005400410049004E00530020004D0041005900200042004500200043004F004E0046004900440045004E005400490041004C002C0020004C004500470041004C004C0059002000500052004900560049004C004500470045004400200041004E0044002000500052004F0054004500430054004500440020004200590020004C00410057002E0020004100430043004500530053002000420059002000540048004500200049004E00540045004E00440045004400200052004500430049005000490045004E00540020004F004E004C005900200049005300200041005500540048004F00520049005300450044002E0020000D000A0049006600200079006F007500200061007200650020006E006F0074002000740068006500200069006E00740065006E00640065006400200072006500630069007000690065006E0074002C00200070006C00650061007300650020006E006F00740069006600790020007400680065002000730065006E00640065007200200069006D006D006500640069006100740065006C007900200061006E006400200064006F0020006E006F007400200064006900730063006C006F00730065002000740068006500200063006F006E00740065006E0074007300200074006F00200061006E00790020006F007400680065007200200070006500720073006F006E002C002000750073006500200069007400200066006F007200200061006E007900200070007500720070006F007300650020006F0072002000730074006F007200650020006F007200200063006F00700079002000740068006500200069006E0066006F0072006D006100740069006F006E002000770069007400680069006E0020006F006E0074006F00200061006E00790020006D0065006400690075006D002E00200050006C0065006100730065002000640065006C0065007400650020007400680069007300200065006D00610069006C00200069006600200072006500630065006900760065006400200069006E0020006500720072006F0072002E000D000A000D000A00Just can't figure this one out.
Developers Jos Posted May 3, 2007 Developers Posted May 3, 2007 (edited) Your inputfile has a Hex 0x00 in there? The current Beta version will return a Binary string when it detects this. Edited May 3, 2007 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
AmphetaMarinE Posted May 3, 2007 Author Posted May 3, 2007 Your inputfile has a Hex 0x00 in there? The current Beta version will return a Binary string when it detects this.Nope, input file is exactly as stated above at the moment, and no 0x00 anywhere.It is a plain text file.Or have I misunderstood you?I'm still pretty new to autoit.
November Posted May 3, 2007 Posted May 3, 2007 Hi again! Try a simple test! Create a new txt file, copy and paste the example that you gave here. save as txt file and try to run the script! just for troubleshoot! Cheers Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font]
Developers Jos Posted May 3, 2007 Developers Posted May 3, 2007 Nope, input file is exactly as stated above at the moment, and no 0x00 anywhere.It is a plain text file.Or have I misunderstood you?I'm still pretty new to autoit.Are you running with the Beta version of AutoIt3 ... 3.2.3.???What happens when you run with v3.2.2.0 ?How did you create the file ? ( maybe attach it so I can check ?)I think that the empty file is returned with 3.2.2.0 and the Hexstring with 3.2.3.? .....When that is the case I am 99% sure your file contains a Hex 0x00 at the beginning of the file . SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
AmphetaMarinE Posted May 3, 2007 Author Posted May 3, 2007 Hi again!Try a simple test!Create a new txt file, copy and paste the example that you gave here. save as txt file and try to run the script!just for troubleshoot!CheersWow,If only I could think as logically as that november!!Thank you.Something must be up with my input file It works fine after doing the same thing you mentioned.JdeB,The file was originally from the signature files produced by MS Outlook.I have kept a master copy and only ever copied it to my working folder.Have you any idea where I should look to see if there is a 0x00 at the beginning of the file?Thank you both so much for your help
Developers Jos Posted May 3, 2007 Developers Posted May 3, 2007 Have you any idea where I should look to see if there is a 0x00 at the beginning of the file?Thank you both so much for your help Open it with a program that can show a file in Hex like Hxd (HExEditor) or PSPad. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
November Posted May 3, 2007 Posted May 3, 2007 Hehehehe Today i helped you...maybe tomorrow i need yours! Cheers. And remember... the best scripts its the one that works Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font]
Uten Posted May 3, 2007 Posted May 3, 2007 Open the fil ewith a hex editor. xvi32 should do. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
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