[ SOLVED ] Delete Script and Script's root folder?
Moderator: DosItHelp
-
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
[ SOLVED ] Delete Script and Script's root folder?
Was looking at the post on self deleting the batch script and was curious if it's also possible to not only self delete the batch file but also the root folder that it resides in (not subdirectories)..Any takers? Thanks DP
Last edited by Dos_Probie on 18 Jun 2013 07:25, edited 1 time in total.
Re: Delete Script and Script's root folder?
Well if you delete the folder the batch file is in then you don't need to worry about deleting the batch file.
Just back up one directory and do an rmdir /s /q
Just back up one directory and do an rmdir /s /q
Re: Delete Script and Script's root folder?
most likely not going to work if Windows Explorer has the folder open with the batch file in it. So you would need to execute it from the previous directory or kill the explorer window that has that folder open and then kill itself.
Code: Select all
C:\batch>dir /ad /b
deleteme
C:\batch>dir /b .\deleteme\*
deleteme.bat
C:\batch>.\deleteme\deleteme.bat
C:\batch>dir /ad /b
C:\batch>
-
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
Re: Delete Script and Script's root folder?
Let me explain this is what I have ..
C:\MyFolder with Clean.bat residing in it ..
I can run on the last line of clean.bat the below script but that only deletes the bat file, other files and any subdirectories in the MyFolder but not the MyFolder root directory..Any ideas? or is this even possible?
C:\MyFolder with Clean.bat residing in it ..
I can run on the last line of clean.bat the below script but that only deletes the bat file, other files and any subdirectories in the MyFolder but not the MyFolder root directory..Any ideas? or is this even possible?
Code: Select all
start cmd /c rd /s/q "%~dp0"&exit /b
Re: Delete Script and Script's root folder?
As I said in my previous post, if you had Windows Explorer open to Myfolder it is not going to delete MyFolder because it is in use by Windows. You would need to kill any applications that have the folder in use. Basically you would need to use TASKKILL to kill explorer then do the RMDIR command but that will kill all explorer windows on Windows 7.
-
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
Re: Delete Script and Script's root folder?
Ok, thanks anyway.. taskkill /f /im explorer.exe not a good option since that will just blue screen and your unable to run a start explorer command to get back to windows, so guess can't be done
Re: Delete Script and Script's root folder?
taskkill explorer will not bluescreen
replace first line with taskkill
i dont know why would you have the folder opened, but anyway it works
it even works if i have the folder opened in totalcommander
i used something like this one time, but was launching the script from command line
in the same "project" i learned the importance of not naming "path" the variable you plan to RD, and the usefullness of deepfreeze
Code: Select all
pskill explorer
set _pa=%~dp0
cd /d c:\
rd/s/q %_pa%
start explorer.exe
replace first line with taskkill
i dont know why would you have the folder opened, but anyway it works
it even works if i have the folder opened in totalcommander
i used something like this one time, but was launching the script from command line
in the same "project" i learned the importance of not naming "path" the variable you plan to RD, and the usefullness of deepfreeze
-
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
Re: Delete Script and Script's root folder?
zpimp wrote:taskkill explorer will not bluescreenCode: Select all
pskill explorer
set _pa=%~dp0
cd /d c:\
rd/s/q %_pa%
start explorer.exe
replace first line with taskkill
i dont know why would you have the folder opened, but anyway it works
it even works if i have the folder opened in totalcommander
i used something like this one time, but was launching the script from command line
in the same "project" i learned the importance of not naming "path" the variable you plan to RD, and the usefullness of deepfreeze
Zpimp, Thanks for the suggestion, while your script above will delete-remove the batch and root directory It
still causes a bsod but your variable idea led me to this script that will Work removing the batch and root directory
(without any bsod or 3rd party pskill file!) with the native taskkill command..DP
Code: Select all
@echo off
:: SELF DESTRUCT (All Files, Subdirectories and Root Directory)
taskkill /f /im explorer.exe>nul 2>&1
set _sd=%~dp0
cd /d c:\
start cmd /c rd/s/q "%_sd%">nul 2>&1&start explorer.exe>nul 2>&1