Recursive copy/rename function

Here is my solution, using Opus to get the details (filenames and number of copies to make) and VBScript to create the copies (since there isn't a good way to loop in Opus directly).

I've attached a zip file containing the button and the VBScript, but they're also listed below so that people don't have to download the zip just to see how it works.

First, the Opus button:

@set NumDupes = {dlgstring|Number of duplicates to create:|10} "C:\Users\Leo\Desktop\DupeFile.vbs" {filepath$} {$NumDupes}

Of course, change the C:\Users\Leo\Desktop part to match where you've put DupeFile.vbs.

I created a NumDupes variable so that the button will work better when multiple files are selected. If it is used like that then it will ask once for the number of duplicates to make and then make that many copies of each selected file.

You can change the "10" in the button if you want a different default number of copies.

Here's the same button in XML format so you can paste it directly into a toolbar:

<?xml version="1.0"?> <button display="both" label_pos="right"> <label>Create Multiple Duplicates</label> <icon1>#duplicate</icon1> <function type="normal"> <instruction>@set NumDupes = {dlgstring|Number of duplicates to create:|10}</instruction> <instruction>&quot;C:\Users\Leo\Desktop\DupeFile.vbs&quot; {filepath$} {$NumDupes}</instruction> </function> </button>

Finally, here is the DupeFile.vbs which does most of the work:

[code]option explicit

Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")

Dim args
set args = WScript.Arguments

if args.Count <> 2 then
MsgBox "DupeFile.vbs: Wrong number of arguments." & vbCRLF & vbCRLF & "Give the full path to the file to duplicate as the first arg." & vbCRLF & vbCRLF & "Give the number of copies to make as the second arg."
WScript.Quit 1
end if

Dim InputFilePath
InputFilePath = args.Item(0)

Dim NumberOfCopies
NumberOfCopies = args.Item(1)

Dim PadTo
PadTo = Len(CStr(NumberOfCopies))

If NumberOfCopies <= 0 Or PadTo = 0 Then
MsgBox "DupeFile.vbs: Number of copies must be a number greater than zero."
WScript.Quit 1
End If

If fs.FolderExists(InputFilePath) Then
MsgBox "DupeFile.vbs: """ & InputFilePath & """ is a folder. Only files are supported."
WScript.Quit 1
End If

If Not fs.FileExists(InputFilePath) Then
MsgBox "DupeFile.vbs: """ & InputFilePath & """ cannot be found."
WScript.Quit 1
End If

Dim LastDot
Dim LastSlash1
Dim LastSlash2

LastDot = InStrRev(InputFilePath, ".")
LastSlash1 = InStrRev(InputFilePath, "")
LastSlash2 = InStrRev(InputFilePath, "/")

Dim LeftPart
Dim RightPart

If LastDot > LastSlash1 And LastDot > LastSlash2 Then
LeftPart = Left(InputFilePath, LastDot - 1)
RightPart = Right(InputFilePath, Len(InputFilePath) - (LastDot - 1))
Else
LeftPart = InputFilePath
RightPart = ""
End If

Dim CurrentNum
Dim OutputFilePath
Dim StrNum

For CurrentNum = 1 To NumberOfCopies
StrNum = CStr(CurrentNum)

If Len(StrNum) < PadTo Then
	StrNum = String(PadTo - Len(StrNum), "0") & strNum
End If

OutputFilePath = LeftPart & "_" & StrNum & RightPart

fs.CopyFile InputFilePath, OutputFilePath, False

Next[/code]
Create Multiple Duplicates.zip (1.14 KB)