Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PowerShell中复制多个文件夹时,如何更改文件夹的名称?_Powershell_Copy - Fatal编程技术网

在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
}