styles3000 Posted December 30, 2009 Share Posted December 30, 2009 I'm wanting to replace a string within a file. The problem I'm having is that I'm coming from the clipboard. I've been trying to send what was copied without shellexecuting. Is it possible to StringReplace from the clipboard to a file without opening it? expandcollapse popupGlobal $hFile Global $SomeTxt Global $StartPos, $EndPos Global $Find_This, $Find_This_Too Global $MyResult $Find_This = "<googlecode>" $Find_This_Too = "</googlecode>" $hFile = FileOpen("D:\Objects To Burn\Adsense\websites\HOME-MASTER-PHP2.htm ",0) ;Open file in read mode If @error Then MsgBox(0,"Warning", "Unable to open file") Exit EndIf $SomeTxt = FileRead($hFile) ;reads the complete file FileClose($hFile) $StartPos = StringInStr($SomeTxt,$Find_This) + StringLen($Find_This) ;finds the first string and puts the pos direct behind the found string If $StartPos = 0 Then ;means $Find_This not found, no need to continue MsgBox(0,"Warning", "Unable to find: " & $StartPos) Exit Else ConsoleWrite("$StartPos= " & $StartPos & @CRLF) ;not needed just added to check if code works EndIf $EndPos = StringInStr($SomeTxt,$Find_This_Too,0,1,$StartPos) ;finds the first occurence of $Find_This_Too after $Start_pos If $EndPos = 0 Then ;means $Find_This_Too was not found, no need to continue MsgBox(0,"Warning", "Unable to find: " & $EndPos) Exit Else ConsoleWrite("$EndPos= " & $EndPos & @CRLF) ;not needed just added to check if code works EndIf $MyResult = (StringMid($SomeTxt,$StartPos,$EndPos-$StartPos)) $MyResult = StringStripWS($MyResult,3) If StringLen($MyResult) <> 0 Then MsgBox(0,"Finished", "You were looking for: " & $MyResult ) $text_from_clip = ClipGet() ;Takes the result off the clipboard $result = StringReplace($SomeTxt, $MyResult, $text_from_clip) Clipput($Result) ;Put the result on the clipboard Else MsgBox(0,"Warning", "Unable to find the wanted string") EndIf Sleep(5000) ShellExecute("D:\Objects To Burn\Adsense\websites\HOME-MASTER-PHP2.htm ") Sleep(5000) Send("{ALTDOWN}{ALTUP}e") Sleep(500) Send("a") Sleep(500) Send("{CTRLDOWN}v{CTRLUP}") Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 30, 2009 Share Posted December 30, 2009 I'm wanting to replace a string within a file. The problem I'm having is that I'm coming from the clipboard. I've been trying to send what was copied without shellexecuting. Is it possible to StringReplace from the clipboard to a file without opening it?You want to write to a file without opening it...? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
styles3000 Posted December 31, 2009 Author Share Posted December 31, 2009 You want to write to a file without opening it...? My bad, that was a poor choice of words. I do want to go into the file but without opening it on my desktop. In other words, I want to open it in a "behind the scenes" kind of way. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted December 31, 2009 Share Posted December 31, 2009 My bad, that was a poor choice of words. I do want to go into the file but without opening it on my desktop. In other words, I want to open it in a "behind the scenes" kind of way.Use FileOpen and FileWrite then. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
styles3000 Posted December 31, 2009 Author Share Posted December 31, 2009 Use FileOpen and FileWrite then.thanks 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