Solved

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

Posted on 2009-04-02
6
674 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Update a registry value to every user hive 15 81
Copy from network drive to local computer using batch 7 45
how to blend these txt lines in a random way? 8 49
batch script 3 37
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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