Skip to content

Instantly share code, notes, and snippets.

@sergebat
Created February 1, 2017 13:24
Show Gist options
  • Select an option

  • Save sergebat/78db4f4e9271ee600137893d46aaf682 to your computer and use it in GitHub Desktop.

Select an option

Save sergebat/78db4f4e9271ee600137893d46aaf682 to your computer and use it in GitHub Desktop.
Create multiple copies of the $file in the same directory
# 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