Yesterday I needed to create and recreate on demand a folder full of test files, because I needed to prevent system-caching from changing the speed at which the test set was operated on.
It has some nice goodies in it, and I thought I'd try them out with a little project to automate creating my test sets.
It makes for some nicely compact and very fast code. (Sub-1-second on my system.)
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/05/10 09:50
# dMod: 2017/05/10 10:10
# Appl: Files.osax
# Task: Create a Folder with a given number of test files from a template.
# Libs: None
# Osax: Files.osax, Satimage.osax
# Tags: @Applescript, @Script, @Files.osax, @Satimage.osax, @Create, @Folder,@Number, @Test, @Files, @Template
------------------------------------------------------------------------------
set numberOfTestFiles to 1000
set targetFolder to "~/Downloads/Test_1000_Files"
set templateFile to POSIX path of ((path to home folder as text) & "test_directory:Many_Files_1000:test_file_0001.txt")
set baseName to "Test_File_"
try -- fail if directory already exists
set targetFolder to mkdir targetFolder with recursively -- create directory tree as necessary
end try
repeat with i from 1 to numberOfTestFiles
set newFileName to baseName & (format i into "0000") & ".txt"
set resultFilesList to filecopy templateFile to targetFolder name newFileName with replacing
end repeat
------------------------------------------------------------------------------
Enjoy.