Windows Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsWindows Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 28th, 2006, 12:07 PM
jennashton jennashton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 140 jennashton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 5 m 12 sec
Reputation Power: 7
Deleting files older than 14 days using Batch file script

Hi,

This sounds easy, but I'm a newbie so it's a lot harder for me.

I am attempting to write a Batch script to delete any files that are older than 14 days in my D:\xxdirectory\ and D:\yydirectory\ and subdirectories.

Here is what I have so far...

HUNT D:\xxdirectory\*.* s q b#-21 "del" e u

I'm not sure if this is even correct. Please help!

Reply With Quote
  #2  
Old June 29th, 2006, 11:35 AM
Dameon51 Dameon51 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 291 Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 21 h 33 m 46 sec
Reputation Power: 44
Send a message via ICQ to Dameon51
What is the hunt command???

I don't think you can actually delete files with standard DOS commands through a batch, but what we can do is XCOPY the files with a certain date to a folder, then delete the folder...

xcopy has a /d switch that you can use to specify the date of the files you want to move, for example....

xcopy *.* /d:04-12-2006 e:\temp

would move all files in the current directory with the date of april 12 2006 on them to e:\temp....

So move your files over to a certain location then run

rmdir e:\temp

That will remove the temp folder, and all the files within it.

Hope this helps.

Last edited by Dameon51 : June 29th, 2006 at 11:48 AM.

Reply With Quote
  #3  
Old June 29th, 2006, 06:05 PM
jennashton jennashton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 140 jennashton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 5 m 12 sec
Reputation Power: 7
What about DELTREE? I found the below script online and was wondering if this will work?
Code:
@ECHO OFF

IF "%1" == "" GOTO NO-DIRECTORY  Prompts if No Directory was Specified

ECHO.                            Displays a Blank Line.
ECHO.                            Displays a Blank Line.

TREE %1                          Displays the Directory Structure
                                    to be Deleted.
DELTREE %1                       Deletes Directory Structure.
DR
GOTO END                         Directs DOS to End the Batch File 
                                    Operation.

:NO-DIRECTORY
ECHO.
ECHO   No Directory Specified
ECHO.

:END

Reply With Quote
  #4  
Old June 29th, 2006, 07:46 PM
Axweildr's Avatar
Axweildr Axweildr is offline
'fie' on me, allege-dly
Click here for more information.
 
Join Date: Mar 2003
Location: in da kitchen ...
Posts: 12,123 Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)  Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 1 Week 1 Day 20 h 31 m 29 sec
Reputation Power: 4323
Send a message via Google Talk to Axweildr
Orkut
with a name like that you're lucky, instant brand recognition ... sure, you're so cute, any self confessed geek would fall over backwards to ... oooh, my head ...
__________________
--Ax
without exception, there is no rule ...
heavyhaulage.ie
Targeted Advertising Cookie Optout (TACO) extension for Firefox
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
-- Jamie Zawinski
Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...

Reply With Quote
  #5  
Old June 30th, 2006, 09:46 AM
Dameon51 Dameon51 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 291 Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 21 h 33 m 46 sec
Reputation Power: 44
Send a message via ICQ to Dameon51
Quote:
Originally Posted by Axweildr
with a name like that you're lucky, instant brand recognition ... sure, you're so cute, any self confessed geek would fall over backwards to ... oooh, my head ...




????? What?? lol

No, that code had nothing to specify the date did it??? Also, is deltree still alive and kicking in winxp? I thought it died with win9x. I could be horribly wrong though.

Reply With Quote
  #6  
Old June 30th, 2006, 10:16 AM
Axweildr's Avatar
Axweildr Axweildr is offline
'fie' on me, allege-dly
Click here for more information.
 
Join Date: Mar 2003
Location: in da kitchen ...
Posts: 12,123 Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)  Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 1 Week 1 Day 20 h 31 m 29 sec
Reputation Power: 4323
Send a message via Google Talk to Axweildr
Orkut
Code:
C:\Documents and Settings\Ax>deltree /?
'deltree' is not recognized as an internal or external command,
operable program or batch file.


XP SP2

Reply With Quote
  #7  
Old June 30th, 2006, 12:12 PM
aitken325i's Avatar
aitken325i aitken325i is offline
At a NO MA'AM meeting . . . .
Dev Shed God 18th Plane (13500 - 13999 posts)
 
Join Date: Mar 2004
Location: nr Edinburgh, Scotland
Posts: 13,723 aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)aitken325i User rank is General 21st Grade (Above 100000 Reputation Level)  Folding Points: 10110 Folding Title: Novice Folder
Time spent in forums: 5 Months 2 Weeks 4 Days 21 h 50 m 35 sec
Reputation Power: 2383
'deltree' only went as far as Windows ME - if you need to use a command along the same lines, use 'del' or 'rmdir'.
Comments on this post
Axweildr agrees: 4got about the replacements ...
__________________
The No Ma'am commandments:

1.) It is O.K. to call hooters 'knockers' and sometimes snack trays
2.) It is wrong to be French
3.) It is O.K. to put all bad people in a giant meat grinder
4.) Lawyers, see rule 3
5.) It is O.K. to drive a gas guzzler if it helps you get babes
6.) Everyone should car pool but me
7.) Bring back the word 'stewardesses'
8.) Synchronized swimming is not a sport
9.) Mud wrestling is a sport

Reply With Quote
  #8  
Old July 6th, 2006, 01:22 PM
jennashton jennashton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 140 jennashton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 5 m 12 sec
Reputation Power: 7
Thanks, I'll just keep on reading and searching. I noticed a lot of the stuff found googleing are old posts. I have no clue to batch programming, sorry. My forte is in web design so I thought people might be able to help me.

I certainly don't expect people to write code for me just because I'm female and I believe this site is devshed not match.com.

Reply With Quote
  #9  
Old July 6th, 2006, 01:30 PM
jennashton jennashton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 140 jennashton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 5 m 12 sec
Reputation Power: 7
Quote:
Originally Posted by Dameon51
What is the hunt command???

I don't think you can actually delete files with standard DOS commands through a batch, but what we can do is XCOPY the files with a certain date to a folder, then delete the folder...

xcopy has a /d switch that you can use to specify the date of the files you want to move, for example....

xcopy *.* /d:04-12-2006 e:\temp

would move all files in the current directory with the date of april 12 2006 on them to e:\temp....

So move your files over to a certain location then run

rmdir e:\temp

That will remove the temp folder, and all the files within it.

Hope this helps.


This helps a lot thanks. However, I don't think you can execute rmdir with files inside the directory with batch. I tried using del and that seems to work with a prompt. Need to figure how to bypass the prompt.

Reply With Quote
  #10  
Old July 6th, 2006, 02:09 PM
Dameon51 Dameon51 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 291 Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 21 h 33 m 46 sec
Reputation Power: 44
Send a message via ICQ to Dameon51
Quote:
Originally Posted by jennashton
This helps a lot thanks. However, I don't think you can execute rmdir with files inside the directory with batch.


Try with the /q and /s switches and i think it should work.

So it would look like...... rmdir /s /q e:\temp

Reply With Quote
  #11  
Old July 6th, 2006, 02:15 PM
jennashton jennashton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 140 jennashton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 5 m 12 sec
Reputation Power: 7
Quote:
Originally Posted by Dameon51
Try with the /q and /s switches and i think it should work.

So it would look like...... rmdir /s /q e:\temp


Another question, xcopy seems to copy the file, how do I move the files? I know in Unix command you can do a mv command, is it the same for DOS? Is it safe to use mv command in batch?

Reply With Quote
  #12  
Old July 6th, 2006, 02:20 PM
Axweildr's Avatar
Axweildr Axweildr is offline
'fie' on me, allege-dly
Click here for more information.
 
Join Date: Mar 2003
Location: in da kitchen ...
Posts: 12,123 Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)Axweildr User rank is General 50th Grade (Above 100000 Reputation Level)  Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1Folding Points: 140379 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 1 Week 1 Day 20 h 31 m 29 sec
Reputation Power: 4323
Send a message via Google Talk to Axweildr
Orkut
it's a rename or ren command, but doesn't work across drives, can you install perl on the machine in question?

Reply With Quote
  #13  
Old July 6th, 2006, 02:22 PM
Dameon51 Dameon51 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 291 Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level)Dameon51 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 21 h 33 m 46 sec
Reputation Power: 44
Send a message via ICQ to Dameon51
Problem. I'm a dumb @$$. Xcopy will only copy the files, not move them, so you'll still have them. I found this little batch on the web for you, but I haven't had time to disect it to see if it works yet...
Also, it seems you are unfamiliar with scripts, so this might be a little complicated for you, but you'll learn something at least! Plus DOS scripts don't really get more complicated than this, so if you figure this out, dos batch files will be a breeze of you.


Code:
:: --------DELOLD.BAT----------
@echo off
SET OLDERTHAN=%1
IF NOT DEFINED OLDERTHAN GOTO SYNTAX

for /f "tokens=2" %%i in ('date /t') do set thedate=%%i

set mm=%thedate:~0,2%
set dd=%thedate:~3,2%
set yyyy=%thedate:~6,4%

set /A dd=%dd% - %OLDERTHAN%
set /A mm=%mm% + 0

if /I %dd% GTR 0 goto DONE
set /A mm=%mm% - 1
if /I %mm% GTR 0 goto ADJUSTDAY
set /A mm=12
set /A yyyy=%yyyy% - 1

:ADJUSTDAY
if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
if %mm%==12 goto SET31

goto ERROR

:SET31
set /A dd=31 + %dd%
goto DONE

:SET30
set /A dd=30 + %dd%
goto DONE

:LEAPCHK
set /A tt=%yyyy% %% 4
if not %tt%==0 goto SET28
set /A tt=%yyyy% %% 100
if not %tt%==0 goto SET29
set /A tt=%yyyy% %% 400
if %tt%==0 goto SET29

:SET28
set /A dd=28 + %dd%
goto DONE

:SET29
set /A dd=29 + %dd%

:DONE
if /i %dd% LSS 10 set dd=0%dd%
if /I %mm% LSS 10 set mm=0%mm%
for %%i in (*.*) do (
set FileName=%%i
call :PROCESSFILE %%~ti
)

set mm=
set yyyy=
set dd=
set thedate=
goto EXIT

:SYNTAX
ECHO.
ECHO USAGE:
ECHO DELOLD X
ECHO   Where X is the number of days previous to Today.
ECHO.
ECHO EX: "DELOLD 5" Deletes files older than 5 days.
GOTO EXIT

:PROCESSFILE
set temp=%1
set fyyyy=20%temp:~6%
set fmm=%temp:~0,2%
set fdd=%temp:~3,2%
if /I %fyyyy% GTR 2069 set fyyyy=19%temp:~6%


:: +*************************************+
:: | This is where the files are deleted |
:: | Change the ECHO command to DEL to   |
:: | delete. ECHO is used for test.      |
:: +*************************************+
if /I %yyyy%/%mm%/%dd% GEQ %fyyyy%/%fmm%/%fdd% (
ECHO %FileName%
)

set temp=
set fyyyy=
set fmm=
set fdd=

:EXIT

:: ----------END-DELOLD.BAT-------------

View Solution

Reply With Quote
  #14  
Old July 6th, 2006, 02:25 PM
jennashton jennashton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 140 jennashton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 5 m 12 sec
Reputation Power: 7
Quote:
Originally Posted by Axweildr
it's a rename or ren command, but doesn't work across drives, can you install perl on the machine in question?


Yes, it is installed and I know it's probably easier to use Perl than batch. Since I'm not familiar with Batch and DOS at all I tought it would be worth learning. Thanks.

Reply With Quote
  #15  
Old July 6th, 2006, 02:27 PM
jennashton jennashton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 140 jennashton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 5 m 12 sec
Reputation Power: 7
Thanks! I'll google for this exact batch and see if I can figure it out. Thanks for helping!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsWindows Help > Deleting files older than 14 days using Batch file script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT