Creating Folder Structure based on Existing Directory Structure


Hi All,

Below is the PowerShell code for Creating Folder Structure based on Existing Directory Structure

workflow parallelCopy {

param([string]$from,[string]$to_dest,[string[]]$ExcludeContent)

$DirArr = @()

$DirArr = Get-ChildItem -Path $from -Exclude $ExcludeContent

foreach –parallel ($dir in $DirArr)

{

inlinescript{

Write-Host "Creating Folder: $($Using:dir.Name)"

Copy-Item $($using:dir.fullname) $using:to_dest -Recurse -Force -Exclude $using:ExcludeContent

}

}

}

$SourceDirectory = Read-Host "Please enter Source Folder"

$DestDirectory = Read-Host "Please enter Destination Folder"

$ExcludeContent = @("*.txt","*.edi","*.PS1","*.xml","*.Zip",”Folder2”) # exclude the folders and file types if you don’t want that

parallelCopy -from $SourceDirectory -to_dest $DestDirectory -ExcludeContent $ExcludeContent

it will create the folders parallelly as we use work flows here.

Regards,

Chaitanya

Leave a comment

Design a site like this with WordPress.com
Get started