Q: Automatically copy files into subfolders
Hi everyone,
I hope I'm posting this in the correct forum - sorry if that's not the case.
I'm trying to find out how to write a script or automator instruction to copy selected files into a folder and also add copies into all it's subfolders automatically.
Basically, I have folder A - which contains two files - and folder B - which contains many files and folders, and many subfolders (many of which also have subfolders). I need an automated process where I can have the two files in folder A copied into each and every folder and subfolder in folder B. It's way too time consuming to do this manually.
Does anyone know of a method to automate this?
Appreciate any help I can get
Thanks,
Florian
MacBook Pro (Retina, 13-inch, Late 2013), OS X Yosemite (10.10.1)
Posted on Jan 28, 2015 5:33 AM
This is pretty easy to do with a recursive script. You do need to be careful, though, that the script doesn't run away and do more than you want/expect.
It isn't clear if this is a one-off script, or if this is something you want to do repeatedly, so the following script might not be ideal, but it asks you for the two folders and copies every file in FolderA into every folder of FolderB:
--prompt the user for the source files/folder
set folderA to (choose folder with prompt "Select the folder with the source files")
set folderB to (choose folder with prompt "Select the destination folder")
-- find the files in the source folder
tell application "Finder" to set sourceFiles to every file of folderA as alias list
-- copy the files to the destination
my copyFiles(sourceFiles, folderB)
on copyFiles(theFiles, theFolder)
log theFolder
-- copy the files
tell application "Finder"
try
duplicate theFiles to folder theFolder
end try
-- iterate through any subfolders:
-- get a list of subfolders
set subFolders to (get every folder of theFolder as alias list)
-- recursively copy the files into those folders
repeat with eachFolder in subFolders
my copyFiles(theFiles, eachFolder)
end repeat
end tell
end copyFiles
Posted on Jan 28, 2015 10:38 AM