chewy Posted December 28, 2004 Share Posted December 28, 2004 I am looking to open a specific text file and need to delete the first 2 characters in the file and then save the file. I am very new to this any help would be appreciated. Thanks Link to comment Share on other sites More sharing options...
DirtyBanditos Posted December 28, 2004 Share Posted December 28, 2004 I am looking to open a specific text file and need to delete the first 2 characters in the file and then save the file. I am very new to this any help would be appreciated.Thanks<{POST_SNAPBACK}>Hi look this tread for exampel and edit it for you) i hope that help you http://www.autoitscript.com/forum/index.php?showtopic=7022 Link to comment Share on other sites More sharing options...
chewy Posted December 28, 2004 Author Share Posted December 28, 2004 i tried this Run('C:\Windows\Notepad.exe "C:\canastotahigh.txt" ') WinActivate("CanastotaHigh.txt - Notepad") Send("{DELETE}") the problem is the window will not keep the focus Link to comment Share on other sites More sharing options...
chewy Posted December 28, 2004 Author Share Posted December 28, 2004 winwaitactive was what i needed Link to comment Share on other sites More sharing options...
DirtyBanditos Posted December 28, 2004 Share Posted December 28, 2004 (edited) i tried thisRun('C:\Windows\Notepad.exe "C:\canastotahigh.txt" ')WinActivate("CanastotaHigh.txt - Notepad")Send("{DELETE}")the problem is the window will not keep the focus<{POST_SNAPBACK}>Hi I use this code exampel edit it for you !Thats wörks great for me i hope that help you! ;AutoItSetOption("MustDeclareVars", 1);AutoItSetOption("MouseCoordMode", 0);AutoItSetOption("PixelCoordMode", 0);AutoItSetOption("RunErrorsFatal", 1);AutoItSetOption("TrayIconDebug", 1);AutoItSetOption("WinTitleMatchMode", 4); ----------------------------------------------------------------------------; Script Start; ---------------------------------------------------------------------------- Run("C:\Programme\DirtyBanditos\Notepad.exe ", "", @SW_MAXIMIZE) WinWait("Notepad.exe ") $ln = StatusbarGetText("Notepad.exe ", "") MsgBox(0, "Title", $ln & @CR & @error) WinWait("Notepad.exe ") Sleep(1000) Send('{Enter}') Edited December 28, 2004 by DirtyBanditos Link to comment Share on other sites More sharing options...
chewy Posted December 28, 2004 Author Share Posted December 28, 2004 got it Run('C:\Windows\Notepad.exe "C:\Documents and Settings\Administrator\Desktop\canastotaMiddle.txt" ') WinWaitActive("CanastotaMiddle.txt - Notepad") Send("{DELETE}") Send("{DELETE}") Send("!f") Send("s") WinClose("CanastotaMiddle.txt - Notepad", "") i was trying too hard Link to comment Share on other sites More sharing options...
DirtyBanditos Posted December 28, 2004 Share Posted December 28, 2004 got it Run('C:\Windows\Notepad.exe "C:\Documents and Settings\Administrator\Desktop\canastotaMiddle.txt" ')WinWaitActive("CanastotaMiddle.txt - Notepad")Send("{DELETE}")Send("{DELETE}")Send("!f")Send("s")WinClose("CanastotaMiddle.txt - Notepad", "")i was trying too hard <{POST_SNAPBACK}> good luky for happy coding! for good exampel use the helpchm.exe from your autoit Install. Link to comment Share on other sites More sharing options...
Coffee Posted December 28, 2004 Share Posted December 28, 2004 There has to be or needs to be a better way to do this with StringTrimLeft on the fly without having to write a whole seperate text file. Link to comment Share on other sites More sharing options...
killaz219 Posted December 28, 2004 Share Posted December 28, 2004 There has to be or needs to be a better way to do this with StringTrimLeft on the fly without having to write a whole seperate text file.<{POST_SNAPBACK}>Maybe something like this?$text = FileRead("file.txt", Filegetsize("file.txt")) $text = StringTrimRight($text, 2) FileDelete("file.txt") FileWrite("file.txt", $text) Link to comment Share on other sites More sharing options...
Coffee Posted December 29, 2004 Share Posted December 29, 2004 no no as this does not work. Basicly a way to read in a line of text from file, edit it and overwrite the the full or partial line of that line in the text file. as a hypothetical this would work: $string = "this is a line of text" $replace = "that is a cool on dood" $text = StringReplace($string, 1, $replace, 1) MsgBox(0, "Title", $text) if the $replace string is longer than the $string however you get undesired results. Not only this but if your going to edit a .txt file you have to rewrite your changes along with the entire old contents of the file. It would be much easier to read in the line you want from a file be it line 1 or line 50, change it, and then overwrite the full OR partial line and only that/those lines in that file ONLY and then close it out rather than edit and rewrite the entire contents of the file. Does this make sense? Link to comment Share on other sites More sharing options...
chewy Posted February 7, 2005 Author Share Posted February 7, 2005 my answer is giving me problem because it is using wordpad instead of notepad on a 98 machine. any more suggestions on this, I cant seem to implement the giving suggestions Link to comment Share on other sites More sharing options...
Blue_Drache Posted February 7, 2005 Share Posted February 7, 2005 (edited) (Parody of "Name that Tune") I can write that code in 9 lines, Jack. #include file.au3 Dim $file, $filearray, $x $file = Fileopen(@scriptdir & "blah.txt",0) _FileReadToArray($file,$filearray) FileClose($file) StringTrimLeft($filearray[1],2) $file = FileOpen(@scriptdir & "blah.txt",2) For $x = 1 to $filearray[0] step 1 FileWriteLine($file,$filearray[$x]) Next Of course, it takes a few assumptions, there's no error checking if the file never opens, and it may not be fast on large text files. Basically, it's reading the text from the file to an array, performs the removal on the first 2 characters as specified, then writes it back to the same file, destroying the previous contents. Edit: Changed String Trim operation from right to left. Oops. Silly me. Edit2: Corrected the FileOpen syntax. Forgot the "" and the @scriptdir tag. Basically, the @scriptdir tag means you have to run the exe from the same directory as the text file you want to modify. Edited February 7, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
phillip123adams Posted February 7, 2005 Share Posted February 7, 2005 I am looking to open a specific text file and need to delete the first 2 characters in the file and then save the file.The simplest and quickest way is to read the entire text file, remove the 1st two characters and re-write the entire text file (unless the file is huge).; Adjust values accordingly $sInFile = "c:\Test.txt"; Input file name $sOutFile = "c:\Test.txt";Output file name )can be same or different than input file name) $iRemoveChars = 2; number of characters to remove from 1st line. _RemoveLeadingCharsFromFile($sInFile, $sOutFile, $iRemoveChars) MsgBox(4096, "All Done!", "The first " & $iRemoveChars & " characters have been removed from: " & @lf & $sInFile & @lf & @lf & "and written to:" & @lf & $sOutFile) Exit Func _RemoveLeadingCharsFromFile($sInFile, $sOutFile, $iRemoveChars) Local $sAll, $hFile $sAll = FileRead($sInFile, FileGetSize($sInFile)) $hFile = Fileopen($sOutFile, 2) FileWrite($hFile, stringmid($sAll, $iRemoveChars + 1)) FileClose($hFile) EndFunc Phillip Link to comment Share on other sites More sharing options...
chewy Posted February 7, 2005 Author Share Posted February 7, 2005 the file is about 100K or so Link to comment Share on other sites More sharing options...
phillip123adams Posted February 7, 2005 Share Posted February 7, 2005 the file is about 100K or so<{POST_SNAPBACK}>I just tried the script I suggested on a 104KB file, and it took 9.65 milliseconds to reconstruct the file without the first 2 characters on the first line. Phillip Link to comment Share on other sites More sharing options...
chewy Posted February 8, 2005 Author Share Posted February 8, 2005 i tried phillips response and get the following error Link to comment Share on other sites More sharing options...
chewy Posted February 8, 2005 Author Share Posted February 8, 2005 you were missing the count parameter in the stringmid, works good now! thanks for the help! Link to comment Share on other sites More sharing options...
phillip123adams Posted February 8, 2005 Share Posted February 8, 2005 you were missing the count parameter in the stringmid, works good now! thanks for the help!<{POST_SNAPBACK}>Glad you got it working. I think the syntax of the StringMid function was changed a month or so ago to make the count parameter optional. Are you using the latest version of AutoIt? Version 3.1.0.15 was released yesterday, and it is no longer beta. Get it while it's hot! Phillip Link to comment Share on other sites More sharing options...
chewy Posted February 8, 2005 Author Share Posted February 8, 2005 boy I spoke too soon, if I write it to a different filename than the original it is fine, but if the output file is the same as the input file the output file is blank Link to comment Share on other sites More sharing options...
phillip123adams Posted February 8, 2005 Share Posted February 8, 2005 boy I spoke too soon, if I write it to a different filename than the original it is fine, but if the output file is the same as the input file the output file is blank<{POST_SNAPBACK}>I just tried it again with the input and output file being the same, and it works for me. What did you use for the "count" parameter?Post your script and I'll check it out. Phillip 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