Page 1 of 1

Deleting folders

Posted: 13 Jun 2018 04:26
by jamesgross
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

Re: Deleting folders

Posted: 13 Jun 2018 12:26
by Meerkat
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