pshankland Posted November 2, 2006 Share Posted November 2, 2006 Have got the following code: While 1 If FileExists("P:\Ado\APS2\Seres-bb.pj") = 1 Then $MyFile = FileOpen("P:\Ado\APS2\Seres-bb.pj", 0) $strModelNumber = FileReadLine($MyFile, 1) ; Reads the Model Number $strSoftwareVers = FileReadLine($MyFile, 2) ; Reads the Software Version $strSDSize = FileReadLine($MyFile, 3) ; Reads the SD Card size FileClose($MyFile) $strTemp = FileDelete($MyFile) If $strTemp = 1 Then MsgBox(0, "Deleted", "") Else MsgBox(0, "NOT Deleted", "") EndIf ExitLoop Else Sleep (5000) ; retry EndIf WEnd I have put the MsgBox entries in simply for debugging as I cannot get the file to ever delete, and the debugging proves this. Where have I gone wrong? Thanks. Link to comment Share on other sites More sharing options...
herewasplato Posted November 2, 2006 Share Posted November 2, 2006 Have you tested your FileClose?While 1 If FileExists("P:\Ado\APS2\Seres-bb.pj") = 1 Then $MyFile = FileOpen("P:\Ado\APS2\Seres-bb.pj", 0) $strModelNumber = FileReadLine($MyFile, 1) ; Reads the Model Number $strSoftwareVers = FileReadLine($MyFile, 2) ; Reads the Software Version $strSDSize = FileReadLine($MyFile, 3) ; Reads the SD Card size $strTemp = FileClose($MyFile) If $strTemp = 1 Then MsgBox(0, "Closed", "") Else MsgBox(0, "NOT Closed", "") EndIf FileDelete($MyFile) ExitLoop Else Sleep(5000) ; retry EndIf WEndIf the file closes and deletes with that test code, then perhaps there needed to be some time between FileClose and FileDelete... time provided by the msgbox above. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Jango Posted November 2, 2006 Share Posted November 2, 2006 FileOpen returns the handle of the file but FileDelete need the path and file name as argument Link to comment Share on other sites More sharing options...
stampy Posted November 2, 2006 Share Posted November 2, 2006 I think it's that filedelete needs the path not the handle. Try this... expandcollapse popupWhile 1 If FileExists("P:\Ado\APS2\Seres-bb.pj") = 1 Then $MyFile = FileOpen("P:\Ado\APS2\Seres-bb.pj", 0) $strModelNumber = FileReadLine($MyFile, 1) ; Reads the Model Number $strSoftwareVers = FileReadLine($MyFile, 2) ; Reads the Software Version $strSDSize = FileReadLine($MyFile, 3) ; Reads the SD Card size $strTemp = FileClose($MyFile) If $strTemp = 1 Then MsgBox(0, "Closed", "") Else MsgBox(0, "NOT Closed", "") EndIf FileDelete("P:\Ado\APS2\Seres-bb.pj") ExitLoop Else Sleep(5000) ; retry EndIf WEnd If the file closes and deletes with that test code, then perhaps there needed to be some time between FileClose and FileDelete... time provided by the msgbox above. pshankland Posted Today, 05:45 AM Have got the following code: CODE: AutoIt While 1 If FileExists("P:\Ado\APS2\Seres-bb.pj") = 1 Then $MyFile = FileOpen("P:\Ado\APS2\Seres-bb.pj", 0) $strModelNumber = FileReadLine($MyFile, 1) ; Reads the Model Number $strSoftwareVers = FileReadLine($MyFile, 2) ; Reads the Software Version $strSDSize = FileReadLine($MyFile, 3) ; Reads the SD Card size FileClose($MyFile) $strTemp = FileDelete($MyFile) If $strTemp = 1 Then MsgBox(0, "Deleted", "") Else MsgBox(0, "NOT Deleted", "") EndIf ExitLoop Else Sleep (5000) ; retry EndIf WEnd goodluck Link to comment Share on other sites More sharing options...
herewasplato Posted November 2, 2006 Share Posted November 2, 2006 (edited) FileOpen returns the handle of the file but FileDelete need the path and file name as argumentDoh - I totally missed that. Perhaps FileDelete should accept a handle... Edit: on second thought, that might not be possible. Edited November 2, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
pshankland Posted November 2, 2006 Author Share Posted November 2, 2006 Thanks everyone for the help. The following worked: While 1 If FileExists("P:\Ado\APS2\Seres-bb.pj") = 1 Then $MyFile = FileOpen("P:\Ado\APS2\Seres-bb.pj", 0) $strModelNumber = FileReadLine($MyFile, 1) ; Reads the Model Number $strSoftwareVers = FileReadLine($MyFile, 2) ; Reads the Software Version $strSDSize = FileReadLine($MyFile, 3) ; Reads the SD Card size $strTemp = FileClose($MyFile) If $strTemp = 1 Then MsgBox(0, "Closed", "") Else MsgBox(0, "NOT Closed", "") EndIf FileDelete("P:\Ado\APS2\Seres-bb.pj") ExitLoop Else Sleep (5000) ; retry EndIf WEnd It is a shame that you can't parse a variable to FileDelete(), but never mind. Thanks. Link to comment Share on other sites More sharing options...
MHz Posted November 2, 2006 Share Posted November 2, 2006 It is a shame that you can't parse a variable to FileDelete(), but never mind.Ofcourse you can. That is not an variable with a filepath string but a file handle. The only reason that your original code fails is you cannot FileDelete a handle. $FullPath = "P:\Ado\APS2\Seres-bb.pj" While 1 If FileExists($FullPath) = 1 Then $MyFile = FileOpen($FullPath, 0) $strModelNumber = FileReadLine($MyFile, 1) ; Reads the Model Number $strSoftwareVers = FileReadLine($MyFile, 2) ; Reads the Software Version $strSDSize = FileReadLine($MyFile, 3) ; Reads the SD Card size FileClose($MyFile) $strTemp = FileDelete($FullPath) If $strTemp = 1 Then MsgBox(0, "Deleted", "") Else MsgBox(0, "NOT Deleted", "") EndIf ExitLoop Else Sleep (5000) ; retry EndIf WEnd 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