在PowerShell中复制多个文件夹时,如何更改文件夹的名称?
这是我现在的代码:在PowerShell中复制多个文件夹时,如何更改文件夹的名称?,powershell,copy,Powershell,Copy,这是我现在的代码: [int]$NumberOfProfiles = Read-Host "Enter the number of Portable Firefox profiles You need" $WhereToWrite = Read-Host "Enter the full path where You'd like to install the profiles" $Source = Get-Location $FolderName = "JonDoFoxPortable" $
[int]$NumberOfProfiles = Read-Host "Enter the number of Portable Firefox profiles You need"
$WhereToWrite = Read-Host "Enter the full path where You'd like to install the profiles"
$Source = Get-Location
$FolderName = "JonDoFoxPortable"
$SourceDirectory = "$Source\$Foldername"
$Copy = Copy-Item $SourceDirectory $WhereToWrite -Recurse -Container
while ($NumberOfProfiles -ge 0) {$Copy; $NumberOfProfiles--}
正如您现在看到的,它只是覆盖了文件夹,但我需要它来复制在
$NumberOfProfiles
中声明的一定数量的文件夹(例如$NumberOfProfiles=10
),并使jondoxportable1、jondoxportable2。。。JondoxPortable10 像这样的方法应该会奏效:
while ($NumberOfProfiles -ge 0) {
$DestinationDirectory = Join-Path $WhereToWrite "$Foldername$NumberOfProfiles"
Copy-Item $SourceDirectory $DestinationDirectory -Recurse -Container
$NumberOfProfiles--
}
或者,可能更简单,像这样的事情:
0..$NumberOfProfiles | % {
$DestinationDirectory = Join-Path $WhereToWrite "$Foldername$_"
Copy-Item $SourceDirectory $DestinationDirectory -Recurse -Container
}
这应该可以为您做到: 替换:
while ($NumberOfProfiles -ge 0) {$Copy; $NumberOfProfiles--}
与:
这将从0循环到$NumberOfProfiles
,并复制到名为$WhereToWrite
的位置,并附上迭代编号$\uuu
(0..$NumberOfProfiles) | % {
Copy-Item $SourceDirectory "$WhereToWrite$_" -Recurse -Container
}