• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

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

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
cmtropical
Asked:
cmtropical
  • 3
  • 2
1 Solution
 
cmtropicalAuthor Commented:
I wanted to add that on WinAT, I will be running the script everyday so it is done ona daily basis.
0
 
Shift-3Commented:
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
 
cmtropicalAuthor Commented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
t0t0Commented:
Run the following 2-line batch file...

@echo off
forfiles -p"\\server1\share\abc" -d-30 -c"cmd /c del @FILE"
0
 
t0t0Commented:
cmtropical

Was my provious comment helpful? Do you need further assistance?
0
 
cmtropicalAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now