Powershell查找最新文件并在文件资源管理器中打开



这是基于另一个问题:https://stackoverflow.com/a/9675811/14529561.

如何从gci path | sort LastWriteTime | select -last 1传递结果并使用explorer.exe打开?

我试过:

$wd = gci path | sort LastWriteTime | select -last 1;
explorer $wd
gci path | sort LastWriteTime | select -last 1 | Format-Table -hidetableheaders | explorer $_.
gci path | sort LastWriteTime | select -last 1 | Format-Table -hidetableheaders | ii $_.

不幸的是,以上所有的都给了我错误。

您可以引用PSParentPath属性。

Get-ChildItem -Path path |
Sort-Object -Property LastWriteTime |
Select-Object -Last 1 | Foreach-Object {
Invoke-Item $_.psparentpath
}

你可以这样做:


$Mypath=$Env:Temp
gci $Mypath | sort LastWriteTime | select -last 1 | % { Explorer /n,/select,$_.FullName }

如果你想在多个文件夹中进行探索,你可以把它们放在一个数组中,然后这样做:


cls
$Mypath=@("$Env:UserProfiledesktop","$Env:Temp","$Env:AppData")
ForEach ($P in $Mypath) {
gci $P | sort LastWriteTime | select -last 1 | % { Explorer /n,/select,$_.FullName }
}

相关内容

最新更新