Deleting folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jamesgross
Posts: 1
Joined: 13 Jun 2018 04:22

Deleting folders

#1 Post by jamesgross » 13 Jun 2018 04:26

Hi gang,

I am trying to delete folders with wildcards within the "wstemp" directory the folders are all named "anonymous" with different end dates like "anonymous20180613" I want them all deleted when this script is run for the past 180 days / 6 months, I have attached what I have, I have tried numerous things but I keep missing something.

Code: Select all

@ECHO OFF
ECHO Backing up wstemp
xcopy /i wstemp wstemp.backup /e
ECHO Deleting anonymous files in wstemp...
ECHO OFF
timeout 3
RMDIR E:\Dmgr01\wstemp\anonymous*     (THIS IS THE LINE THAT ISN'T WORKING PROPERLY)
ECHO Deleting backup...
ECHO OFF
timeout 3
rmdir /s /q wstemp.backup
@ECHO OFF
Last edited by Squashman on 13 Jun 2018 06:40, edited 2 times in total.
Reason: MOD EDIT: Please use descriptive thread titles and please use [code][/code] tags.

Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Re: Deleting folders

#2 Post by Meerkat » 13 Jun 2018 12:26

Apparently, rd/rmdir doesn't support wildcards. Change the problematic line with this instead:

Code: Select all

for /d %%x in ("E:\Dmgr01\wstemp\anonymous*") do rmdir "%%x"
Wherein for /d allows you to loop through directories. Here's a link for more information: https://ss64.com/nt/for_d.html

Meerkat

Post Reply