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 do!

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top