Achilles Posted August 13, 2007 Posted August 13, 2007 (edited) I'm having problem with self delete. Well, to be 100% accurate the problem is with the directory that contains the file being deleted. I have made a program that has a simple install/uninstall, however the uninstall is not deleting the folder it made when it installed the program. (I believe that this is because it contains a file that is currently being used)Here my problem in a nutshell. Warning: Pay heed to the message box, it will try to delete the folder! I don't know if this will work on your computer but I would suggest putting this script in a folder by itself just to be safe!$splitFullPath = StringSplit(@ScriptFullPath, '\') $dirToDelete = '' For $a = 1 to $splitFullPath[0] - 1 $dirToDelete &= $splitFullPath[$a] & '\' Next $dirToDelete = StringTrimRight($dirToDelete, 1) $pass = Msgbox(52, 'Warning', 'We are going to try to delete this folder: ' & @CRLF & $dirToDelete & @CRLF & 'Proceed?') If $pass = 6 then _SelfDelete() DirRemove($dirToDelete) EndIf Func _SelfDelete($iDelay = 0) Local $sCmdFile FileDelete(@TempDir & "\scratch.bat") $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _ & ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'del ' & @TempDir & '\scratch.bat' FileWrite(@TempDir & "\scratch.bat", $sCmdFile) Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE) EndFunc Edited August 29, 2007 by Piano_Man My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
gamerman2360 Posted August 13, 2007 Posted August 13, 2007 Could install to a folder next to the script... Then just delete that folder when your done. Even better yet, the %TEMP% folder. The problem with your script is that it's trying to delete a folder with an open file (your script). If you changed _SelfDelete to delete the directory, it would work.
The Kandie Man Posted August 13, 2007 Posted August 13, 2007 You can't tell the script to remove that directory because the script is running out of that directory. I modified the SelfDelete function to work for you: $splitFullPath = StringSplit(@ScriptFullPath, '\') $dirToDelete = '' For $a = 1 to $splitFullPath[0] - 1 $dirToDelete &= $splitFullPath[$a] & '\' Next $dirToDelete = StringTrimRight($dirToDelete, 1) ConsoleWrite("Directory to delete:" & $dirToDelete) $pass = Msgbox(52, 'Warning', 'We are going to try to delete this folder: ' & @CRLF & $dirToDelete & @CRLF & 'Proceed?') If $pass = 6 then _SelfDelete() EndIf Func _SelfDelete($iDelay = 0) Local $sCmdFile FileDelete(@TempDir & "\scratch.bat") $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _ & ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & ':loop2' & @CRLF _ & 'rmdir /q "' & $dirToDelete & '"' & @CRLF _ & 'if exist "' & $dirToDelete & '" goto loop2' & @CRLF _ & 'del ' & @TempDir & '\scratch.bat' FileWrite(@TempDir & "\scratch.bat", $sCmdFile) Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE) EndFuncoÝ÷ ÚÚºÚ"µÍ[È ÌÎNÜYÜÈÜH ][ÝÉÌÎNÈ [È ÌÍÙÑ[]H [È ÌÎNÉ][ÝÉÌÎNÈ [ÈÔ I hope that is what you were looking for. The Kandie Man ;-) "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire
Achilles Posted August 13, 2007 Author Posted August 13, 2007 (edited) You can't tell the script to remove that directory because the script is running out of that directory. I modified the SelfDelete function to work for you: $splitFullPath = StringSplit(@ScriptFullPath, '\') $dirToDelete = '' For $a = 1 to $splitFullPath[0] - 1 $dirToDelete &= $splitFullPath[$a] & '\' Next $dirToDelete = StringTrimRight($dirToDelete, 1) ConsoleWrite("Directory to delete:" & $dirToDelete) $pass = Msgbox(52, 'Warning', 'We are going to try to delete this folder: ' & @CRLF & $dirToDelete & @CRLF & 'Proceed?') If $pass = 6 then _SelfDelete() EndIf Func _SelfDelete($iDelay = 0) Local $sCmdFile FileDelete(@TempDir & "\scratch.bat") $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _ & ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & ':loop2' & @CRLF _ & 'rmdir /q "' & $dirToDelete & '"' & @CRLF _ & 'if exist "' & $dirToDelete & '" goto loop2' & @CRLF _ & 'del ' & @TempDir & '\scratch.bat' FileWrite(@TempDir & "\scratch.bat", $sCmdFile) Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE) EndFunc I hope that is what you were looking for. The Kandie Man ;-)Nice, that works perfectly! Thanks a lot! With the original _SelfDelete() I tried removing the @ScriptFullPath and replacing it with $dirToRemove but it didn't work, and now I see why... Edited August 13, 2007 by Piano_Man My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
SuperFlyChetGuy Posted August 24, 2007 Posted August 24, 2007 Excuse my ignorance but, how do you use this? The SuperFlyChetGuy
Achilles Posted August 24, 2007 Author Posted August 24, 2007 Excuse my ignorance but, how do you use this?If you want to uninstall a program you can tell it to do this once it's done uninstall everything.The actual self delete and delete the files directory would be used to delete the directory that the file was in. I use it to delete the folder that the uninstall was in. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
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