Script to delete files starting with X and older than N days – HELP

5 pts.
Tags:
LPT
VBScipt
Windows
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

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 
}

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following