如何在目录中获取包含最旧LastWriteTime的文件?

pen*_*ake 0 powershell

如果我有一个带通配符的完整路径,我怎样才能获得最旧的LastWriteTime文件?

$fullpath = "myFolder:\foooBar*.txt"
$theOldestFile = # What to write to get among the 
                 #fooBar*.txt that has the max LastWriteTime?
Run Code Online (Sandbox Code Playgroud)

CB.*_*CB. 5

像这样:

$fullpath = "myFolder:\foooBar*.txt"
$theOldestFile = dir $fullpath | sort lastwritetime | select -First 1
Run Code Online (Sandbox Code Playgroud)