开发者

Powershell prevent recursive lookup of parent folder only search child folders

I have created a script which can find all files in a provided directory of a specified format. The script will recursivly search the folder structure for these files.

    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

The problem is that if i provide the path C:\scripts\files as my root search directory the script still searches through C:\scripts as well as C:\scripts\files\ which is all I wish the script to d开发者_运维问答o!

This is obviously a simple fix but I am unsure what I have coded wrong.

Thanks in advance, Craig


You have a typo in the variable name you're listing: $soureDir vs $sourceDir

Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜