我正在尝试获取具有特定扩展名的所有文件的列表。
(...)$_.Extension -eq ".$ext"
我从控制台读取扩展到脚本。
我的问题是如何查找扩展名为 .*
的文件?
编辑:
这是其余的代码:
$setOfFolders = (Get-ChildItem -Path D:\ -Directory).name
Write-host "Set last write date " -ForegroundColor Yellow -NoNewline
$ostZmiana= read-host $exten = read-host "Set extensions "
ForEach ($f in $setOfFolders)
{
$saveTofile = "C:\Users\pziolkowski\Desktop\Outs\$f.txt"
Get-ChildItem -Path D:\Urzad\Wspolny\$f -Recurse | ? {$_.LastAccessTime -lt $ostZmiana -and $_.Extension -eq ".$exten"} | % {Get-acl $_.FullName} |sort Owner | ft -AutoSize -Wrap Owner, @{Label="ShortPath"; Expression= $_.Path.Substring(38)}} > $saveToFile
}
最佳答案
您还可以在 Get-ChildItem 上使用 -filter:
Get-ChildItem -Filter“*.txt”
你也可以指定递归:
Get-ChildItem -Recurse -Filter“*.txt”
关于powershell - 搜索时的文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18871063/