Repository navigation
Stuck with Powershell script #24771
Replies: 2 comments
|
Enumerate only the immediate contract folders, then build the matching sibling destination from each folder's name. The For copying the files directly inside each contract folder into the matching sibling's $root = 'C:\Users\Documents\script'
$source = Join-Path $root 'contracts'
Get-ChildItem -LiteralPath $source -Directory | ForEach-Object {
$destination = Join-Path (Join-Path $root $_.Name) 'Documents'
New-Item -ItemType Directory -Path $destination -Force | Out-Null
Get-ChildItem -LiteralPath $_.FullName -File | ForEach-Object {
Copy-Item -LiteralPath $_.FullName -Destination $destination -WhatIf
}
}Review the |

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi all,
I want to create a Powershell script for the following:
So from here: C:\Users\Documents\script\contracts\ [subfolder with customer number] \file(s) (there are multiple subfolders)
To there: C:\Users\Documents\script\ [new created subfolder with customer number] \copy file(s) here
This is what I have so far, but I'm getting stuck:
The problem is that the the new folder I want to create is also be created in the "old" contracts folder and subfolders. I want to skip this. I only want the new folder to be created in C:\Users\Documents\script[contract number folder] and not in C:\Users\Documents\script[contract number folder]\subfolder(s)
All reactions