【发布时间】:2017-10-31 16:09:41
【问题描述】:
我必须在相当大的文件窗口文件共享中搜索从我公司发送和接收的传真。我是 Python 2.7 的新手,但我确实找到了这个 powershell find-child-item 脚本,它工作得很好。
该脚本允许我输入搜索路径,然后搜索关键字或短语。 (当我搜索可能包含 400k 到 100 万个传真文件的文件夹时,这非常有用,这些文件的文件名中都有发件人/收件人编号。
但脚本运行缓慢,我不太关心 powershell。谁能帮我转换一下?
谢谢!
#>
"`n"
write-Host "---------------------------------------------" -ForegroundColor Yellow
$filePath = Read-Host "Please Enter File Path to Search"
write-Host "---------------------------------------------" -ForegroundColor Green
$fileName = Read-Host "Please Enter File Name to Search"
write-Host "---------------------------------------------" -ForegroundColor Yellow
"`n"
Get-ChildItem -Recurse -Force $filePath -ErrorAction SilentlyContinue |
Where-Object { ($_.PSIsContainer -eq $false) -and
( $_.Name -like "*$fileName*") } |
Select-Object Name,Directory |
Format-Table -AutoSize *
write-Host "------------END of Result--------------------" -ForegroundColor Magenta
pause
# end of the script
【问题讨论】:
-
它运行缓慢,因为您没有在
Get-ChildItem上使用-Filter或-File。学习口头禅:向左过滤,向右格式化。 -
@TheIncorrigible1 虽然有些人没有使用最新的 PowerShell。所以他们可能无法在他们的命令中使用
-Filter或-File。 -
@ShawnEsterman
-Filter从 v1.0 开始就存在了。-File在 v3.0 中引入。
标签: python-2.7 file powershell finder