Nam G VU
Nam G VU

Reputation: 35404

What is the windows batch command to remove a path regardless it is file or folder?

Let's say we have a file or a folder named c:\temp and we need to remove it if it exists.

What is the command to do it?

Upvotes: 1

Views: 420

Answers (4)

DarthJDG
DarthJDG

Reputation: 16591

Err... why not do both? :)

rd /q /s c:\temp
del /q c:\temp

One of them will succeed if C:\temp is either a file or a folder and the other one will fail. If both fails, it means that it couldn't be deleted or not found. You can even make it a batch file if you don't want to type both commands in all the time.

Upvotes: 2

Nam G VU
Nam G VU

Reputation: 35404

It is del c:\temp. Sorry I thought it was only used for files and not applicable for folders

Upvotes: 0

user330315
user330315

Reputation:

C:\>rmdir /?
Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

    /S      Removes all directories and files in the specified directory
            in addition to the directory itself.  Used to remove a directory
            tree.

    /Q      Quiet mode, do not ask if ok to remove a directory tree with /S

Upvotes: 2

BugFinder
BugFinder

Reputation: 17868

Err, have you tried

rd c:\temp /q /s

Upvotes: 2

Related Questions