Deleting Directories with BAT File

T

Tim Pafford

Anyone have the command line switches for deleting a
directory under C:\Program Files? I have tried using the
del "directory name" function but that isn't working.
 
A

andrea catto'

depends...
on windows 95/98 use deltree
on NT+ and older... use rmdir /q /s

the problem is.........
there is always something in c:\program files that is in use and therefore
locked...
nice try!!!
 
J

John Doue

andrea said:
depends...
on windows 95/98 use deltree
on NT+ and older... use rmdir /q /s

the problem is.........
there is always something in c:\program files that is in use and therefore
locked...
nice try!!!
I am not sure what you are trying to do. Obviously, while Windows is
running, files will be in use in some directories of \program files.
Deleting them would create problems with Windows, may be disable it. But
if this does not matter because you want to uninstall Windows for
instance, then booting from a Win98 startup diskette and using deltree
will do the job. But first check the diskette to make sure deltree is on
it, I kind of think it is not part of the startup utilities. You would
then have to copy deltree on the harddisk before.

I know some utilities allows to program the deletion of files that are
in use (they get deleted after a reboot). I believe one is called
delaydelete. If you cannot find one, I can email it to you but I have no
experience using it.
 
G

Guest

-----Original Message-----
Anyone have the command line switches for deleting a
directory under C:\Program Files? I have tried using the
del "directory name" function but that isn't working.
.
have you tried deltree? be careful, it deletes
everything that is in the downline directory. For
instance, deltree c:\windows\program files\quicken would
delete everything under the quicken directory. Good Luck!
 
G

Gary Smith

everything that is in the downline directory. For
instance, deltree c:\windows\program files\quicken would
delete everything under the quicken directory. Good Luck!

There's no deltree in Windows 2000. The equivalent command is RD /s.
 
R

R. C. White

Hi, Tim.

The del command deletes FILES, but it never was the command to delete
directories (or folders). In MS-DOS, we used rmdir or rd to Remove
Directory.

In the "DOS" window of Win2K/XP, or on the Command line, we still use rd
<directory>. As with any "DOS" command, we can type rd /? and see a
mini-Help file showing all the switches available for the command. There
are only two switches for rd: /q and /s. The /s switch removes the entire
directory tree, including all subdirectories and all files within them; it
asks "are you sure?" before deleting. The /q switch invokes the Quiet mode,
which removes everything without asking.

So, if you are sure you want to remove the entire directory tree and you
know the name of the directory at the top of the tree, just put one short
line in your batch file (for C:\Program Files\Fubar, for instance):

rd "c:\program files\fubar" /s /q

(The quotes, of course, are needed because of the space in "Program Files".)

RC
 
J

John Doue

R. C. White said:
Hi, Tim.

The del command deletes FILES, but it never was the command to delete
directories (or folders). In MS-DOS, we used rmdir or rd to Remove
Directory.

In the "DOS" window of Win2K/XP, or on the Command line, we still use rd
<directory>. As with any "DOS" command, we can type rd /? and see a
mini-Help file showing all the switches available for the command.
There are only two switches for rd: /q and /s. The /s switch removes
the entire directory tree, including all subdirectories and all files
within them; it asks "are you sure?" before deleting. The /q switch
invokes the Quiet mode, which removes everything without asking.

So, if you are sure you want to remove the entire directory tree and you
know the name of the directory at the top of the tree, just put one
short line in your batch file (for C:\Program Files\Fubar, for instance):

rd "c:\program files\fubar" /s /q

(The quotes, of course, are needed because of the space in "Program
Files".)

RC
I believe you missed a crucial point from Tim's question: how to delete
files which are in use. I hope I addressed that point in my previous
post but we have not heard from Tim anymore.
 
T

Tim Pafford

Thank you to all of you for your suggestions.

Since I am running this in a Win2K environment, I am going
with rd "C:\Program Files\directory name" /s /q. Seems to
work like a champ.

Thanks again for all of the ideas. These will definetly
come in handy in the future.
 
R

R. C. White

Good catch, John.

But Tim has reported success, so I guess it worked out OK. Maybe there were
no in-use files in that particular directory. ;<)

RC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top