Solved

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

Posted on 2009-04-02
6
677 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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