Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

copy folders with subfolders and files

$
0
0

Hello,

i have few lines in PS that are supposed to copy folders with all files and sub folders in them.

here is what i have written:

$dstfolder = read-host "source folder, please"
$srcfolder =  read-host "destination folder, please"

$date = get-date -format  "yyyy.MM.dd"
$dir = "$name2\$date"

if (-not (Test-Path -Path $dir)){
new-Item -type Directory -path $dir
}

$Files = Get-ChildItem -Path $dstfolder | Where-Object { $_ -is [System.IO.DirectoryInfo] -and ($_.Name -ne "docs_1.1")} | Sort-Object -Unique;
$Files | ForEach-object { Copy-Item -Path $_.fullname -Destination $dir };

 

so basically, i am providing source folder with folders that i have to copy and dst folder.

Also i am excluding one of the folders "docs_1.1" which i dont need to be copied, and copy all other directories.

The problem is that script copies only directories and does not copy all the files and subfolders in them.

 

Can you please advice what is wrong with my few lines script ...


Viewing all articles
Browse latest Browse all 6937

Trending Articles