Solved

Batch file to delete files older than 30 days on share drive

Posted on 2009-04-02
6
672 Views
Last Modified: 2012-05-06
I want to create a simple batch file that will run on WinAT to find any files on an specific share name and delete any files older than 30 days.
As an example,  I have a share name such as \\server1\share\abc.  I want anything files older than 30 days to be deleted on the abc folder.
I use WinAT to run batch files so this will be running on the actual server where this share is.  By adding a batch file it will delete anything older than 30 days.  All suggestions on knowlege base does not give me a straight answer such as type this in on WinAT and let it rip.  PLEASE HELLLLPPPP.
0
Comment
Question by:cmtropical
  • 3
  • 2
6 Comments
 

Author Comment

by:cmtropical
ID: 24052268
I wanted to add that on WinAT, I will be running the script everyday so it is done ona daily basis.
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24052495
You can do it using a forfiles command like the one below.  Once you've tested it successfully and are sure it is finding the right files, remove the word ECHO to delete them.

Also, WinAT is deprecated.  Schtasks is a much more functional command for managing scheduled tasks.


forfiles /P "d:\share\abc" /D -30 /C "cmd /c ECHO del /F @path"

Open in new window

0
 

Author Comment

by:cmtropical
ID: 24053613
Shift-3,  I will go ahead and test this first thing tomorrow morning on a none-critical area and see.  I hope this works.  I have no idea why we use WinAT, I may start using Schtasks in the future and transfer all schedules.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:t0t0
ID: 24055605
Run the following 2-line batch file...

@echo off
forfiles -p"\\server1\share\abc" -d-30 -c"cmd /c del @FILE"
0
 
LVL 16

Accepted Solution

by:
t0t0 earned 500 total points
ID: 24136106
cmtropical

Was my provious comment helpful? Do you need further assistance?
0
 

Author Closing Comment

by:cmtropical
ID: 33513645
I was able to run with your command string and was able to produce what I need to do.  I just set this up with my own path and now is running on it's own and is doing it's job.  You saved me alot of time.  Thanks and sorry for adding my comments so late.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now