Haris Ahmed
Haris Ahmed

Reputation: 83

Exclude folder from Recurse in Powershell

I've written the following script to move all MP4 file in a particular folder to the Root folder, however I want the script to ignore one particular folder called "Camera". I'm using the exclude command to no avail. Can anyone help?

$ignore = ("*Camera*");

Get-Childitem "C:\Root" -exclude $ignore -recurse -include *.mp4 | move-item -dest "C:\Root\"

Upvotes: 1

Views: 665

Answers (1)

Loïc MICHEL
Loïc MICHEL

Reputation: 26150

-exclude is to filter filename or extension I dont think you can use it to filter directories. You can try this :

gci c:\root\*.mp4 -recurse |where {$_.fullname -notmatch "camera"}

Upvotes: 4

Related Questions