get childitem - Excluding multiple folders when copying using powershell -
the objective copy folders , files path path using powershell. however, want exclude files , folders getting copied. able exclude multiple files adding them exclude list
get-childitem -path $source -recurse -exclude "web.config","body.css","thumbs.db"
for excluding folders added
$directory = @("bin") ?{$_.fullname -notmatch $directory}
and final copy script looks
get-childitem -path $source -recurse -exclude "web.config","body.css","thumbs.db" | ?{$_.fullname -notmatch $directory} | copy-item -force -destination {if ($_.gettype() -eq [system.io.fileinfo]) {join-path $dest $_.fullname.substring($source.length)} else {join-path $dest $_.parent.fullname.substring($source.length)}}
this seems work single folder, when add multiple folders excluded directories not seem work.what can done exclude multiple folders?
try this:
$excluded = @("web.config", "body.css","thumbs.db") get-childitem -path $source -recurse -exclude $excluded
from comment, in case want exclude folders, can use this:
get-childitem -path $source -directory -recurse | ? { $_.fullname -inotmatch 'foldername' }
or can check container first this:
get-childitem -path $source -recurse | ? { $_.psiscontainer -and $_.fullname -notmatch 'foldername' }
Comments
Post a Comment