Delete directory/folder from command line

by admin on January 2, 2009

We can delete a directory or folder from command line using rmdir command. See syntax below

rmdir directoryname

Examples:

C:\>rmdir emptydir
C:\>
C:\>rmdir nonemptydir
The directory is not empty.
C:\>rmdir /S nonemptydir
nonemptydir, Are you sure (Y/N)? y
C:\>

As you can see in the above examples, we need to use /S to delete a non empty directory.

To delete directory in quiet mode, without being asked for confirmation, we can use /Q switch.

rmdir /Q /S nonemptydir

We can also use ‘rd’ in place of ‘rmdir‘. Both names refer to the same command. This command works on Windows 2000, Windows XP, Server 2003, Vista and Windows 7.

Deleting directory with white spaces in the name :

You can specify the directory name in quotes. See the example below.

rmdir /Q /S “folder with spaces in the name”

{ 14 comments… read them below or add one }

Anonymous February 9, 2010 at 2:50 pm

thnx.

Reply

Anonymous March 31, 2010 at 9:18 am

thanks, I was looking for this!

Reply

Anonymous May 20, 2010 at 9:11 am

thnx

Reply

Anonymous June 13, 2010 at 1:48 pm

Thank you very much

Reply

Anonymous June 22, 2010 at 3:56 pm

tanx buddy…..

Reply

Anonymous August 27, 2010 at 10:23 am

Thank you my friend

Reply

Brian November 26, 2010 at 2:05 pm

Thanks dude..I was looking for command line way of deleting nonempty folders.. cheers!!!

Reply

Anonymous January 13, 2011 at 4:35 pm

good post ……..

Reply

Anonymous February 15, 2011 at 5:30 am

Good old DOS….something tells me one day the world will be saved by a DOS operation. ; )

Reply

Anonymous July 23, 2011 at 8:40 am

cannot delete… access is denied. am trying to delete a directory on a flash drive. cannot access permissions because explorer isn't working. using win7

Reply

Diman December 15, 2011 at 4:09 am

Note:
Don’t forget to leave a “space” in the command line..
rmdir /Q /S_“folder with spaces in the name” I meant “space”, ait’t “underscore”. And upper case of “S”. Good luck!

Reply

chetan January 9, 2012 at 1:04 am

Hi
can you show me an example of command to delete this path in bat file.
C:\Program Files\Microsoft Office Communicator

am not able to do this . some error s

Reply

admin February 2, 2012 at 4:19 pm

Is this in Windows 7/Vista?.
If so then you need to take ownership of the files. You can do that with below command from elevated administrator command prompt.
takeown /F "c:\Program Files\Microsoft Office Communicator" /R /A

then run the below command to delete this folder.

rmdir /S "c:\Program Files\Microsoft Office Communicator"

Ashwani February 2, 2012 at 6:40 am

cd program files\microsoft office communicator
then enter press
rd /s “filename”
Then enter

Reply

Leave a Comment

Previous post:

Next post: