Jump to content

How to force directory deletion in DOS


Recommended Posts

Hi Friends,

I have an unattended installer and to un-install it I have a dos script file e.g

C:\MySoftware\uninstall\script.cmd

Now, in script.cmd, I try to delete the "MySoftware" folder by issuing this:

rmdir /S /Q "C:\MySoftware"

But the problem is since the script is inside the folder itself, it deletes everything but cannot delete the two folder and leaves behind these 2 blank folders (MySoftware and uninstall) which the user have to delete manually.

Can someone suggest a way how to handle this in a better way so that the whole "MySoftware" folder gets deleted.

Thanks a lot.

Link to comment
Share on other sites


im not really fluent in dos commands, but i use

RD /S /Q "path"

to remove my files, always works without a hitch

EDIT:

what u can try doing is putting script.cmd in a temp directory or something?

or u can add a registry entry to runonce so that next time u restart u can have the folder gone

but u cant delete a folder that your file is in

Edited by MCT
Link to comment
Share on other sites

You want a self deleting batch? :w00t:

Mind you is RISKY business, however, you need a temp file:

save this snippet in your \Mysoftware\uninstall directory, naming it selfdel.cmd or something like that

ECHO del %~dpnx0>%~d0\delnow.cmd
ECHO RD /S /Q %~dp0>>%~d0\delnow.cmd
ECHO del %~d0\delnow.cmd>>%~d0\delnow.cmd
%~d0\delnow.cmd

(this will just remove the two batch files and the \uninstall\ subdirectory - just in case - but you can modify it with hardcoded paths to have it remove also the main \mysoftware one)

Some more details and examples here:

http://catch22.net/tuts/selfdel

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Thanks Guys,

The copying to TEMP directory idea worked like a charm.

I just wrote another batch script like you said and copied it to the TEMP directory before executing the "Rmdir" command...

Cheers...

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...