我正在想办法解决这个问题
例如路径
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
答案1
尝试一下 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。
答案2
## 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