Я пытаюсь найти решение для этого
напр. paths
C:\Designs\CustomerA\PhotoshopFiles\
C:\Designs\CustomerB\PhotoshopFiles\
C:\Designs\CustomerC\PhotoshopFiles\
Я хочу переместить папку PhotoShopFiles в другую (Клиентские файлы Photoshop) и переименовать эту папку, взяв имя папки, в которой она содержалась.
Итак, у меня могла быть такая структура:
C:\Designs\Customer Photoshop Files\CustomerA
C:\Designs\Customer Photoshop Files\CustomerB
C:\Designs\Customer Photoshop Files\CustomerC
Сделайте снимок для powershell
$newLocation = "C:\Designs\Customer Photoshop Files"
$folders = Get-ChildItem C:\Designs\ | select name, fullname
foreach ($folder in $folders) {
Move-Item -Path $folder.fullname\PhotoshopFiles\ -Destination $newLocation\$folder.name -whatif
}
Удалите -whatif, если он выглядит хорошо.
## Q:\Test\2018\10\23\sf_936862.ps1
#requires -Version 3.0
Get-ChildItem "C:\Designs" -Directory | Where-Object FullName -Notmatch "Customer Photoshop Files"|ForEach-Object {
$Source = Join-Path $_.FullName "PhotoshopFiles\*"
$Target = Join-Path "C:\Designs\Customer Photoshop Files" $_.Name
If (!(Test-Path $Target)){MD $Target -Force| Out-Null}
Get-ChildItem $Source | Move-Item -Destination $Target -Force
}
Дерево образцов после запуска скрипта:
> tree C: /f
C:\
└───Designs
├───Customer Photoshop Files
│ ├───CustomerA
│ │ a.jpg
│ │
│ ├───CustomerB
│ │ b.jpg
│ │
│ └───CustomerC
│ c.jpg
│
├───CustomerA
│ └───PhotoshopFiles
├───CustomerB
│ └───PhotoshopFiles
└───CustomerC
└───PhotoshopFiles