Method to duplicate one file a thousand times

Dear Forum

Could a kind person give me the simplest method (using Applescript or Automater or another way) to:
– in a selected folder make 1000 copies of every file in that folder with the name prepended with a start number and an end number.

In other words, if the selected folder contains one file called ‘sample.txt’ then running the process with start=1 and end=1000 results in that folder containing 1001 files, all copies of the original file, called ‘1sample.txt’, ‘2sample.txt’, up to ‘1000sample.txt’, as well as the original ‘sample.txt’

I am running MacOS 10.13.3

Thank you. Philip Caplan

Model: MacBookAIr
AppleScript: Script Editor v2.10
Browser: Safari 537.36
Operating System: macOS 10.13

Using Finder:


set aFolder to choose folder

tell application "Finder"
	repeat with aFile in (every file of aFolder) as alias list
		set baseName to name of aFile
		repeat with i from 1 to 1000
			set name of (duplicate aFile) to (i as text) & baseName
		end repeat
	end repeat
end tell

Many thanks, KniazidisR.

That works, but I had hoped there would be a dialog where I could enter a “start” number and an “end” number, as that would give me greater flexibility over the names and number of files created.

Would you (or somebody) be able to give me a revised script with that function added?

Many thanks. Philip


set aFolder to choose folder
set firstNum to text returned of (display dialog "Enter a number" default answer "1") as integer
tell application "Finder"
	repeat with aFile in (every file of aFolder) as alias list
		set baseName to name of aFile
		repeat with i from firstNum to (firstNum + 999)
			set name of (duplicate aFile) to (i as text) & baseName
		end repeat
	end repeat
end tell

It’s boring to have to guess what is really asked for.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 19:50:15

Hi Yvan

I ran your script but it didn’t give me “a dialog where I could enter a “start” number and an “end” number” as I asked. It just went ahead and created 1000 copies!

:frowning: Philip

set aFolder to choose folder
set twoNums to text returned of (display dialog "Enter first number, last number" default answer "1,2")
try
	set {t1, t2} to my decoupe(twoNums, ",")
on error
	error "“" & twoNums & "” aren‘t two numbers separated by a comma"
end try
try
	set {n1, n2} to {t1 as integer, t2 as integer}
on error
	error "“" & twoNums & "” aren‘t two numbers separated by a comma"
end try
if n1 > n2 then
	set bof to n1
	set n1 to n2
	set n2 to bof
end if

tell application "Finder"
	repeat with aFile in (every file of aFolder) as alias list
		set baseName to name of aFile
		repeat with i from n1 to n2
			set name of (duplicate aFile) to (i as text) & baseName
		end repeat
	end repeat
end tell

#=====

on decoupe(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to oTIDs
	return l
end decoupe

#=====

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 21:17:22

Thanks, Yvan. That now works.
All the best and stay safe.
Philip