Listen for multiple file types in Powershell

How do I modify the below code to also listen for .csv files in addition to .xml?

#loop files 
foreach($item in (dir $Dir "*.xml")){ 
    "Uploading $item..." 
    $uri = New-Object System.Uri($ftp+$item.Name) 
    $webclient.UploadFile($uri, $item.FullName)
    Remove-Item $item.FullName 
 } 

Open in new window


Thanks.
Sailing_12PirateAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Use a list of strings with -include:
#loop files 
foreach($item in (dir $Dir -Include *.xml, *.csv)){ 
    "Uploading $item..." 
    $uri = New-Object System.Uri($ftp+$item.Name) 
    $webclient.UploadFile($uri, $item.FullName)
    Remove-Item $item.FullName 
 } 

Open in new window

oBdACommented:
-Include and -Exclude only work if either -Recurse is used, or if a wildcard has been specified together with the path.
This will yield nothing:
Get-ChildItem -Path C:\Windows -Include *.exe

Open in new window

This, however, should come up with a few matches:
Get-ChildItem -Path C:\Windows\* -Include *.exe

Open in new window

And best practice is to avoid aliases (which can be redefined) in scripts. They're of course fine when working directly in the console, but in scripts, the real cmdlet names should be used.
#loop files
$FileTypes = "*.xml", "*.csv"
ForEach ($item in (Get-ChildItem "$($Dir)\*" -Include $FileTypes)) { 
	"Uploading $($item.Name)..."
	$uri = New-Object System.Uri($ftp+$item.Name)
	$webclient.UploadFile($uri, $item.FullName)
	Remove-Item $item.FullName
} 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
oBdA is correct, I assumed dir $Dir "*.xml" already uses the -include parameter, but it is -filter instead. And -filter does not allow for multiple conditions.
I also agree that you usually should not use the alias in scripts, but was ignoring that for this question ;-).
Sailing_12PirateAuthor Commented:
Thanks for your thorough evaluation and  the additional feedback
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.