这是我现在的代码:
[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
)并且它会使JonDoFoxPortable1,JonDoFoxPortable2 ... JonDoFoxPortable10。
答案 0 :(得分:1)
这样的事情应该有效:
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
}
答案 1 :(得分:1)
这应该适合你:
取代:
while ($NumberOfProfiles -ge 0) {$Copy; $NumberOfProfiles--}
使用:
(0..$NumberOfProfiles) | % {
Copy-Item $SourceDirectory "$WhereToWrite$_" -Recurse -Container
}
这将从0循环到$NumberOfProfiles
并复制到名为$WhereToWrite
的位置,并附加迭代编号$_