Miguel Vega

Quick Tip - Recursively Delete Files

Ever had to delete files from a directory where the files' last write time is older than a specific date? If so, the following snippet might come in handy:

$path = "\\server\folder"

$olderThan = (Get-Date).AddDays(-1)

Get-ChildItem -Path $path -Recurse | Where-Object { !$_.PSIsContainer -and $_.LastWriteTime -lt $olderThan } | Remove-Item -Force

The above code will recursively delete all files where the "LastWriteTime" is older than the date specified.

If you are as paranoid as I am, feel free to append the "-WhatIf" switch at the end of the command to display all the files that would be deleted without actually deleting them.

Hello World

Starting this new blog to share my experiences as a Software Engineer whose responsibilities includes developing enterprise applications with C# and the .NET framework.

I will be posting guides, snippets and other random thoughts. There is more to come so please stay tuned.

Copyright © 2020 - Design by FS