即時通訊目前試圖讓一個腳本來做到以下幾點:PowerShell的 - txt文件搜索
搜索文件的位置和獲得任何txt文件,.INI,config文件。 在來自用戶的輸入上過濾此文件。 將所有文件移到某個位置。
我有一個問題試圖餵養變量,它可能真的很簡單,但即時通訊正在努力弄清楚我需要做什麼而不需要手動分割字符串。有任何想法嗎?
$QQ = Read-Host -Prompt "String your searching for:"
$QL = Read-Host -Prompt "Enter the file location you wish to search:"
$FT = Get-ChildItem -Path "$QL" -recurse | where {$_.extension -eq ".txt"} | % {$_.fullname}
$FI = Get-ChildItem -Path "$QL" -recurse | where {$_.extension -eq ".ini"} | % {$_.fullname}
$FC = Get-ChildItem -Path "$QL" -recurse | where {$_.extension -eq ".config"} | % {$_.fullname}
$FTS = Get-Content -Path "$FT" -Filter "$QQ"
$FIS = Get-Content -Path "$FI" -Filter "$QQ"
$FCS = Get-Content -Path "$FC" -Filter "$QQ"
$FD = "C:\Search-$QQ"
$FD1 = Get-ChildItem $FD
function folder {
if ($FD -eq $Null) {New-Item "$FD" -ItemType directory}}
function search{
if ($FTS -ne $null){Copy-Item -Path $ft -Destination "$fd" | Write-Host "$FT" | Format-List}
if ($FIS -ne $null){Copy-Item -path $fi -Destination "$fd" | Write-Host "$FI" | Format-List}
if ($FCS -ne $null){Copy-Item -Path $fc -destination "$fd" | Write-Host "$FC" | Format-List}
}
folder
search;
正在接收錯誤的一個例子是:(很明顯,它處理的字符串作爲一個在多個文件的問題)
獲取內容:找不到路徑「C: \ test \ Test \ 1c.config C:\ test \ Test \ 2c.config C:\ test \ Test \ 3c.config',因爲它不存在。
伊夫固定它myselfjust需要將$ FT,$ FI,$ FC上的報價從$ FTS,$ FIS,$ FCS變量中刪除。 –