5 pts.
 Script to delete files starting with X and older than N days – HELP
The title says it all! I have a folder that contains files that start with LPT and all have different suffixes. So, I need a script that finds this list of files and deletes any of them older than say 5 days.

Software/Hardware used:
Windows OS
ASKED: February 5, 2013  2:42 PM
UPDATED: February 5, 2013  2:48 PM

Answer Wiki:
You can do this fairly simply using Powershell. Script provided as is and I am not responsible for any undesired results. The script is written to delete files so be careful and test first. See Below:
$path = "path to delete from"
$date = Get-Date
$checkdate = $date.adddays(-5)
#$checkdate
$files = ls $path | where{$_.name -like "LPT*"} | where{$_.lastaccesstime -lt $checkdate}
foreach($file in $files)
{
Remove-Item $path$file 
}
Last Wiki Answer Submitted:  February 11, 2013  4:48 pm  by  Colin Smith   845 pts.
All Answer Wiki Contributors:  Colin Smith   845 pts. , Michael Tidmarsh   11,380 pts. , anonnynon   5 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Take a look at this similar question.  You could modify the proposed script to fit your needs: Help with VB Script to delete old files and subfolders

 63,535 pts.