Link to home
Start Free TrialLog in
Avatar of kpbarem
kpbarem

asked on

How to delete files with with specific naming pattern that is over 24 hours old

I'm not very familiar with batch but i'm trying to create a script that deletes pdf files in a specific folder that is over 24 hours old.

The pattern is C:\Schedules\Schedule####.pdf with #### being a 4 digit number randomly generated number.  Could anyone help me out?
Thanks in advance!
Avatar of Paul Tomasi
Paul Tomasi
Flag of United Kingdom of Great Britain and Northern Ireland image

What's your date and time formats?

Enter the following commands in DOS:

    echo %date%
    echo %time%

and copy & paste the results in your reply
Avatar of kpbarem
kpbarem

ASKER

Wed 11/07/2012
16:04:01.23
Windows Vista, 7, and 8 have a command line utility called "Forfiles.exe".  I use it to delete all files from a folder older than a certain date.

FORFILES -pe:\foldername -s -m*.* -d-4 -c"CMD /C del @FILE"

Change the foldername and *.* to the pattern that you want to delete.
ASKER CERTIFIED SOLUTION
Avatar of Brian Pringle
Brian Pringle
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you have an older version of Windows, you can download forfiles.exe from the following location.

http://www.microsoft.com/en-us/download/details.aspx?id=7887
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kpbarem

ASKER

Thanks! but these files are actually on multiple servers that are not running Windows 7 or 8.  I was hoping to avoid having to download anything on these servers
You just have to download it on whichever computer runs the command.  The address can be a local folder or a network share.  

Or, you can map the drive in your batch file, issue the command, and then delete the mapped drive.

What OS are the servers running?

I just simply extracted that one file from the AIK and copied it to the computers that need it.  Nothing to install that way.
Are the date and time formats on all tha computers the same?

If so, what do you see when you copy & paste this into DOS?

    copy /y nul "-" >nul & for %a in (-) do @echo %~ta & del "-"
Avatar of kpbarem

ASKER

11/07/2012 04:44 PM
Apologies. I cannot focus on this right now. I will look at this again tomorrow if a solution is not found by then.
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kpbarem

ASKER

I ended up being able to make the forfiles solution work.  I appreciate everyone's help and advice.