2011-08-16 117 views
0

我已經創建了一個腳本,可以找到指定格式的提供的目錄中的所有文件。該腳本將遞歸搜索這些文件的文件夾結構。Powershell防止父文件夾的遞歸查找只搜索子文件夾

Write-host "Please enter source Dir:" 
$soureDir = read-host 

Write-Host "Format to look for with . :" 
$format = read-host 

#Write-host "Please enter output Dir:" 
#$outDir = read-host 

$Dir = get-childitem "$sourceDir" -recurse 

$files = $Dir | where {$_.extension -eq "$format"} 
$files | format-table name 

的問題是,如果我提供的路徑C:\腳本\文件作爲我的根搜索目錄的腳本仍然到C搜索:\腳本以及C:\腳本\ FILES \這是所有我希望腳本去做!

這顯然是一個簡單的修復,但我不確定我編碼錯誤。

由於提前, 克雷格

回答

3

你必須在變量名拼寫錯誤您列出:$ soureDir VS $ sourceDir

試試這個:

get-childitem $sourceDir -Filter $format -recurse | format-table name 
+0

拼寫錯誤!不能相信它! –

+2

謝謝,我修復了你輸入錯誤的錯誤。 :) – JasonMArcher

+0

哈哈,謝謝賈森:) –

相關問題