delete on condition

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
glob5
Posts: 34
Joined: 23 Nov 2010 00:47

delete on condition

#1 Post by glob5 » 19 Aug 2013 08:57

looking for a script that only checks a folder and in the folder if, there is only one folder that starts with "abc_cdf" exits. If there are more than one folder starting with "abc_cdf", delete the ones that are older than 5 days. This script does not go inside the sub folders. It is not recursive.

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

Re: delete on condition

#2 Post by foxidrive » 19 Aug 2013 09:18

How much of the script have you written? :)

glob5
Posts: 34
Joined: 23 Nov 2010 00:47

Re: delete on condition

#3 Post by glob5 » 20 Aug 2013 00:12

popular common easy stuff but not enough.:
for /f "delims=*" %%x in ('dir /b /ad-s-h C:\dirx\abc_cdf*') do rd "%%x" /s /q

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

Re: delete on condition

#4 Post by foxidrive » 20 Aug 2013 00:45

Look into forfiles.exe as it can handle a range of days old and is native to Vista and higher.

xxcopy also has good date handling capability, and is free for personal use.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: delete on condition

#5 Post by penpen » 20 Aug 2013 14:36

Aditionally maybe this thread helps you:
http://www.dostips.com/forum/viewtopic.php?f=3&t=4846

penpen

Post Reply