DROTHISM

Get Oldest File in a Directory

Posted by Drothism on Mar 17th, 2009

Looking for a quick way to get the oldest file in a directory? Here is a quick and dirty method to do it with PowerShell…

dir f:\archive -recurse| ?{!($_.PSIsContainer)} | sort -property lastwritetime | select -first 1

The ?{!($_.PSIsContainer)} filter will leave sub-directories out of the search.

Leave a reply

You must be logged in to post a comment.