Show if folder exist and delete it

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
romasasss
Posts: 2
Joined: 29 Nov 2013 02:39

Show if folder exist and delete it

#1 Post by romasasss » 29 Nov 2013 02:43

Hello. i am new at batch so i need some help with script which check if there is a folder in my selected directory and if there is that folder then delete it.

AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

Re: Show if folder exist and delete it

#2 Post by AiroNG » 29 Nov 2013 02:54

Something like this?

Code: Select all

@echo off
if exists "D:\UnwantedFolder" ( del /q "D:\UnwantedFolder" )

romasasss
Posts: 2
Joined: 29 Nov 2013 02:39

Re: Show if folder exist and delete it

#3 Post by romasasss » 29 Nov 2013 03:02

AiroNG wrote:Something like this?

Code: Select all

@echo off
if exists "D:\UnwantedFolder" ( del /q "D:\UnwantedFolder" )



Yes something like this. but i am getting message that folder was unexpected at this time

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Show if folder exist and delete it

#4 Post by foxidrive » 29 Nov 2013 03:08

There's a typo above, and the trailing slash checks for a folder as opposed to a file too.

RD is used for folders.

Code: Select all

@echo off
if exist "D:\UnwantedFolder\"  rd /s /q "D:\UnwantedFolder"

AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

Re: Show if folder exist and delete it

#5 Post by AiroNG » 29 Nov 2013 03:57

Sorry, my mind was somewhere else when i made that post. :oops:
foxidrive's solution is the correct way.


for /l %%a in (1 1 100) do ( echo: I will reread my written text before i post it! ) :wink:

Post Reply