Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-02
6
Medium Priority
?
703 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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 2000 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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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 …
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 …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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