Computing.Net > Forums > Windows Server 2003 > write a script to delete files 7 da

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

write a script to delete files 7 da

Reply to Message Icon

Name: rpr986
Date: October 7, 2008 at 12:35:43 Pacific
OS: WIN server 2003
CPU/Ram: ???
Product: ????
Comment:

I need to write a script that will delete files that are 7 days old, and i need this script to run once every 24 hours. Where should i start???

if you cant tell i am a newb



Sponsored Link
Ads by Google

Response Number 1
Name: amlife
Date: October 8, 2008 at 07:43:22 Pacific
Reply:

well you can write script and schedule it to
run every 7 days on directory and it will
delete your "7" days old files.

batch files can help you with such task in
windows environment.

and you can schedule it with windows task scheduler.

can you tell us the location of the files you
want to remove and what type of files?

Thanks


0

Response Number 2
Name: rpr986
Date: October 9, 2008 at 05:55:54 Pacific
Reply:

Just say the directory is D:\ftp

The files are normally word documents and sometimes excel sheets. I guess that really doesnt matter, just anything older than 7 days needs to be deleted...

thanks


0

Response Number 3
Name: KReagan
Date: November 3, 2008 at 21:18:16 Pacific
Reply:

You will need a copy of Microsofts robocopy installed and c:\deleted should not exist.

Schedule this to run in task scheduler every 24 hours, it is one single command line

cmd.exe /c for /f "tokens=3,4*" %I in ('robocopy d:\ftp c:\deleted *.bat *.txt /s /minage:7 /L /FP ^| find /i "new file"') do del %J


0

Response Number 4
Name: KReagan
Date: November 3, 2008 at 22:30:52 Pacific
Reply:

How about
forfiles /p d:\ftp /m *.* /d -y /s /c "cmd /c del @path"


0

Response Number 5
Name: KReagan
Date: November 3, 2008 at 22:33:54 Pacific
Reply:

sorry, syntac error, should be
forfiles /p d:\ftp /m *.* /d -7 /s /c "cmd /c del @path"


0

Related Posts

See More



Response Number 6
Name: rpr986
Date: November 4, 2008 at 05:24:33 Pacific
Reply:

What will happen to the folder if all the files in it are gone? What will happen if the folder is older than 7 days but the files are newer than 7 days?

The script was good, but then i came up with these issues...


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows Server 2003 Forum Home


Sponsored links

Ads by Google


Results for: write a script to delete files 7 da

Script to share and unshare a file www.computing.net/answers/windows-2003/script-to-share-and-unshare-a-file/5734.html

script to report file types www.computing.net/answers/windows-2003/script-to-report-file-types/7731.html

unable to delete files www.computing.net/answers/windows-2003/unable-to-delete-files/7364.html