-2

用户输入一个连字符的序列,例如 12-18。我需要从目录中复制一个文件以分隔现有文件夹,所有文件夹都命名为 Folder12、Folder13、Folder14....Folder18。实现这一目标的最佳方法是什么?

4

1 回答 1

1

我不会为您提供整个脚本,但我会回答我认为这个问题的棘手部分:将“12-18”变成 Powershell 可以迭代的东西。

#User Input
$param = "12-18" 

#Split the string by "-", and assign to variables.
$start = $param.Split("-")[0]
$end = $param.Split("-")[1]

# using the ".." range operator you can now iterate through each number
$start..$end | foreach { 
    Write-host $_ 
    #Here is where you can put your file copy code.
}
于 2013-09-17T23:02:23.627 回答