Created
February 1, 2017 13:24
-
-
Save sergebat/78db4f4e9271ee600137893d46aaf682 to your computer and use it in GitHub Desktop.
Create multiple copies of the $file in the same directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create multiple copies of the $file in the same directory | |
| # For example: | |
| # clonefile.ps1 test01.txt 3 --> test02.txt, test03.txt | |
| # clonefile.ps1 test0.png 4 --> test1.png, test2.png, test3.png | |
| param([string]$file, [int]$count) | |
| if (-Not ($file -match "\d+") ) { | |
| "File should contain starting number, for example image020.png" | |
| exit; | |
| } | |
| $initialNumber = [convert]::ToInt32($matches[0]); | |
| $padCount = $matches[0].Length; | |
| $toNumber = $initialNumber + $count; | |
| for ($i = $initialNumber + 1; $i -lt $toNumber; $i++) { | |
| $targetFileName = $file -replace "\d+", [convert]::ToString($i).PadLeft($padCount, "0") | |
| Copy-Item $file $targetFileName | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment