Symplystyc Posted December 11, 2007 Share Posted December 11, 2007 I want my pos.txt file to be deleted inside a loop but for somereason the file refuses to go away. expandcollapse popupWhile $detect > 1 $Title = "http://...........- Microsoft Internet Explorer" $m = 21 $n = 256 $i = 0 For $i =1 to 5 Step 1;~~ just need this to run 5 times $Pos = PixelSearch($m,$n,50,706,0x9C9AFF,0,1);~~ Does a pixel search hopefully $n changes FileOpen("pos.txt",1);~~ opens pos.txt FileWrite("pos.txt",$pos[0] & @CRLF);~~ writes X coord in pos.txt FileWrite("pos.txt",$pos[1] & @CRLF);~~ writes Y coord in pos.txt _FileReadToArray("pos.txt",$array);~~ creates the array $array $n = $pos[1] + 15;~~ Found first pixel with color 0x9C9AFF now lets change $n so that next search starts below previous $m,$n possition. ;~ $i = $i + 1;~~ Counter loop Next FileOpen("dif.txt",0) $d = FileReadLine("dif.txt",1) $e = FileReadLine("dif.txt",2) $x = $array[$d] + 20 $y = $array[$e] WinActivate("Point-N-Click") MouseMove( 20,60 ) Sleep(1500) ;~ WinActivate($Title) MouseMove($x,$y) Sleep(5000) $detect = $detect + 1 _IENavigate($oIE,".........") sleep(500) FileClose("pos.txt") FileRecycle("pos.txt") ;~~~~~~~~TRied filedelete and filerecycle but file does not go away. Sleep(500) If FileExists("pos.txt") Then MsgBox(4096, "pos.txt", "Exists") Else EndIf WEnd The glass is neither half empty nor half full, it is simply twice as big as it needs to be. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 11, 2007 Developers Share Posted December 11, 2007 Don't use the filename in the fileclose but use the handle returned by FileOpen() else the file will remain open until the program ends. 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. Link to comment Share on other sites More sharing options...
Symplystyc Posted December 11, 2007 Author Share Posted December 11, 2007 Don't use the filename in the fileclose but use the handle returned by FileOpen() else the file will remain open until the program ends.what handle? The glass is neither half empty nor half full, it is simply twice as big as it needs to be. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 11, 2007 Developers Share Posted December 11, 2007 (edited) Have you looked at the helpfile description and example ? FileOpen returns a FileHandle that should be used for both the FileWrite and fileclose... Jos Edited December 11, 2007 by Jos 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. Link to comment Share on other sites More sharing options...
Skruge Posted December 11, 2007 Share Posted December 11, 2007 Welcome to the forums! You never really closed the file handle, so it won't be deleted. Take a look at the FileOpen/FileClose examples for more info. Also, when you use FileWrite with a filename, it will open a handle, write the text, then close the handle. You really only need to use FileOpen/FileClose when the reads/writes you plan to make are numerous. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
Albuquerquefx Posted December 11, 2007 Share Posted December 11, 2007 (edited) I can't see exactly what you're doing, but I think a file write is not the answer. It looks like you're using that file to store some temporary data between loops and whatnot; you'd be much better served with another array for comparisions. In any case, regardless of what you think of my suggestion, here's the fix... When you specify the file name directly in the File...() operation, you don't need to do seperate opens, reads, and closes. So, instead of: FileOpen("pos.txt") ... FileWrite("pos.txt","blahblah") FileClose("pos.txt") FileDelete("pos.txt") Edited December 11, 2007 by Albuquerquefx Link to comment Share on other sites More sharing options...
Symplystyc Posted December 11, 2007 Author Share Posted December 11, 2007 Thanks for all the replies. I didnt realize that i needed a handle when using fileopen and I guess I didnt realize that I didnt need fileopen for what I was doing. just using filewrite() then filedelete() did the trick. The glass is neither half empty nor half full, it is simply twice as big as it needs to be. 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