idenniske Posted June 8, 2009 Share Posted June 8, 2009 Hello, Im new with autoIT. i tried to open my file and do a couple of backspaces. What is the correct way to open the file and do 4 backspaces? This is the path to the file: C:\xampp\htdocs\test\kennislong.txt i hope you guys can help me. Link to comment Share on other sites More sharing options...
FinalVersion Posted June 8, 2009 Share Posted June 8, 2009 Use The HelpFile! [center][+] Steam GUI [+][+] Clipboard Tool [+][+] System :: Uptime [+][+] StarCraft II Mouse Trap [+][/center] Link to comment Share on other sites More sharing options...
idenniske Posted June 8, 2009 Author Share Posted June 8, 2009 I did, couldn't find it. You are the pro so please help me Link to comment Share on other sites More sharing options...
FinalVersion Posted June 8, 2009 Share Posted June 8, 2009 I did, couldn't find it. You are the pro so please help meIf you used it, you would of atleast found out how to open & write to a file... [center][+] Steam GUI [+][+] Clipboard Tool [+][+] System :: Uptime [+][+] StarCraft II Mouse Trap [+][/center] Link to comment Share on other sites More sharing options...
water Posted June 8, 2009 Share Posted June 8, 2009 do 4 backspaces? means "delete 4 characters"?So your script would consist of fileread (reads file into a single variable)delete charactersfilewrite (writes file from a single variable) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
idenniske Posted June 8, 2009 Author Share Posted June 8, 2009 $file = FileOpen("C:\xampp\htdocs\test\kennislong.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileClose($file) It won't open my file Link to comment Share on other sites More sharing options...
FinalVersion Posted June 8, 2009 Share Posted June 8, 2009 $file = FileOpen("C:\xampp\htdocs\test\kennislong.txt", 0)If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") ExitEndIfFileClose($file)It won't open my fileAre you using Vista / Win7, And Are You Admin? [center][+] Steam GUI [+][+] Clipboard Tool [+][+] System :: Uptime [+][+] StarCraft II Mouse Trap [+][/center] Link to comment Share on other sites More sharing options...
water Posted June 8, 2009 Share Posted June 8, 2009 Does the file exist?Has it been opened by another application?Can you open it with notepad? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
idenniske Posted June 8, 2009 Author Share Posted June 8, 2009 (edited) I use: windows xp professional and i am administrator the file is not in use, the file exist and i can open it with notepad Edited June 8, 2009 by idenniske Link to comment Share on other sites More sharing options...
idenniske Posted June 8, 2009 Author Share Posted June 8, 2009 means "delete 4 characters"?So your script would consist of fileread (reads file into a single variable)delete charactersfilewrite (writes file from a single variable)Yes i want to delete 4 characters Link to comment Share on other sites More sharing options...
zac23 Posted June 8, 2009 Share Posted June 8, 2009 file open then winactivate then send {backspace} {backspace}{backspace}{backspace} Link to comment Share on other sites More sharing options...
idenniske Posted June 8, 2009 Author Share Posted June 8, 2009 file open then winactivate then send {backspace} {backspace}{backspace}{backspace} Thanks When I run this $file = FileOpen("C:\xampp\htdocs\test\kennislong.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf WinActivate("[CLASS:Notepad]", "") Send ("{backspace}") Send ("{backspace}") Send ("{backspace}") Send ("{backspace}") FileClose($file) my browser opens My Computer, wrong path? Link to comment Share on other sites More sharing options...
water Posted June 8, 2009 Share Posted June 8, 2009 (edited) Thanks When I run this $file = FileOpen("C:\xampp\htdocs\test\kennislong.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf WinActivate("[CLASS:Notepad]", "") Send ("{backspace}") Send ("{backspace}") Send ("{backspace}") Send ("{backspace}") FileClose($file) my browser opens My Computer, wrong path?Your code can't work. FileOpen opens the file to use with FileRead and FileWrite. You can't switch to Notepad because Notepad hasn't been started yet. You're mixing to Autoit "concepts". Concept 1: Read a file, change and write it with pure autoit Concept 2: Open the file with another program (notepad) and do all the work using the GUI of the program. So first you should decide how to do the job. To get you started:How large is your file?Where are the characters you want to delete (the first 4 characters, the last, somewhere in the middle)? Edited June 8, 2009 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
idenniske Posted June 8, 2009 Author Share Posted June 8, 2009 Your code can't work. FileOpen opens the file to use with FileRead and FileWrite. You can't switch to Notepad because Notepad hasn't been started yet.You're mixing to Autoit "concepts".Concept 1: Read a file, change and write it with pure autoitConcept 2: Open the file with another program (notepad) and do all the work using the GUI of the program.So first you should decide how to do the job.To get you started:How large is your file?Where are the characters you want to delete (the first 4 characters, the last, somewhere in the middle)?The file is 849kb and i want to delete the last 4 characters. Link to comment Share on other sites More sharing options...
zac23 Posted June 8, 2009 Share Posted June 8, 2009 oops my bad sorry Link to comment Share on other sites More sharing options...
idenniske Posted June 8, 2009 Author Share Posted June 8, 2009 oops my bad sorryDon't you guys have a example that works so i can test it? Link to comment Share on other sites More sharing options...
picaxe Posted June 8, 2009 Share Posted June 8, 2009 $trimchar = 4 $eol = @CRLF $file1 = "$$$test.txt" $file2 = "$$$test trimmed " & $trimchar & " chars.txt" If FileExists($file1) Then FileDelete($file1) If FileExists($file2) Then FileDelete($file2) $j = "" For $i = 1 To 10000 $j &= "This is line " & $i & " This is line " & $i & " This is line " & $i & " This is line " & $i & $eol Next FileWrite($file1, StringTrimRight($j, 2)) $start1 = TimerInit() $text = FileRead($file1) $readtime = Round(TimerDiff($start1)/1000, 3) ConsoleWrite("file read time: " & $readtime & "sec" & @LF) $start2 = TimerInit() FileWrite($file2, StringTrimRight($text, $trimchar)) ConsoleWrite("create file " & $file2 & " with " & $trimchar & " chars removed from end, time: " & Round(TimerDiff($start2)/1000, 3) & @LF) Link to comment Share on other sites More sharing options...
idenniske Posted June 8, 2009 Author Share Posted June 8, 2009 is it posible to open the notepad so i can see what happens. right now i have this: $fileVariableName = FileOpen("input.txt", 0) If $fileVariableName = -1 Then MsgBox(0,Failure,Failed to open file) Exit EndIf While 1 With a error called : parse error. I'm hopeless Link to comment Share on other sites More sharing options...
water Posted June 8, 2009 Share Posted June 8, 2009 is it posible to open the notepad so i can see what happens.Usually it is more error prone to do something using the GUI. Couldn't you use picaxe's code and test if it does what you need? The stripped down code would look like:$trimchar = 4 $inFile = "C:\xampp\htdocs\test\kennislong.txt" $outFile = "C:\xampp\htdocs\test\kennislong_trimmed.txt" If FileExists($outFile) Then FileDelete($outFile) $text = FileRead($inFile) If $text = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($outFile, StringTrimRight($text, $trimchar)) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
idenniske Posted June 8, 2009 Author Share Posted June 8, 2009 Usually it is more error prone to do something using the GUI. Couldn't you use picaxe's code and test if it does what you need? The stripped down code would look like:$trimchar = 4 $inFile = "C:\xampp\htdocs\test\kennislong.txt" $outFile = "C:\xampp\htdocs\test\kennislong_trimmed.txt" If FileExists($outFile) Then FileDelete($outFile) $text = FileRead($inFile) If $text = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($outFile, StringTrimRight($text, $trimchar)) Thanks guys this works. i do have one more question. It seems that i have a lot of white spaces, so the trimmed chars are spaces. Is it posible to pick out the last four chars ),(, ? 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