Question:
How to exclude folders ? Now I hardcode the folder names but i want it to be more flexible.
1 2 |
foreach($file in Get-ChildItem $fileDirectory -Exclude folderA,folderb) |
Answer:
“How to exclude folders ?” , if you mean all folders :
1 2 |
get-childitem "$fileDirectory\\*" -file |
but it works only for the first level of $fileDirectory .
This works recursevly :
1 2 |
Get-ChildItem "$fileDirectory\\*" -Recurse | ForEach-Object { if (!($_.PSIsContainer)) { $_}} |
or
1 2 |
Get-ChildItem "$fileDirectory\\*" -Recurse | where { !$_.PSisContainer } |