2011-08-16 115 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

哈哈,谢谢贾森:) –

相关问题