pencilCake
pencilCake

Reputation: 53223

How can I get the file with the oldest LastWriteTime in a directory?

If I have a full-path with a wildcard, how can I get the file with the oldest LastWriteTime?

$fullpath = "myFolder:\foooBar*.txt"
$theOldestFile = # What to write to get among the 
                 #fooBar*.txt that has the max LastWriteTime?

Upvotes: 3

Views: 12695

Answers (1)

CB.
CB.

Reputation: 60910

like this:

$fullpath = "myFolder:\foooBar*.txt"
$theOldestFile = dir $fullpath | sort lastwritetime | select -First 1

Upvotes: 10

Related Questions