Freddie February 2016

AppleScript - Paste a file in every folder and sub folder of directory

I have a directory with sub directories. I want to put a file in every folder, without the use of sudo commands. I only want to use apple script code and terminal commands, using the command line:

do shell script ""


The file is called hello.png

I'd love any help! :) Thank you all!

Answers


pbell February 2016

The copy is now done in all sub folders of the main folder (what ever the recursive level is.

The script bellow does what you want :

set MyFile to choose file with prompt "Select file to be duplicated in every folder"
set MyFolder to choose folder with prompt "Select the folder in which you want to copy the file"

tell application "Finder"
set SubFolders to every folder of entire contents of MyFolder
repeat with aFolder in SubFolders
    duplicate MyFile to aFolder
end repeat
end tell

I made assumption that you want to duplicate the selected file to all sub-folders of the selected folder. Then, I did not add recursive search for sub-folders of sub-folders of ...

In this script, I just used Applescript commands. You can replace the "duplicate" line with a do shell script command (using shell command 'cp'). However in this case the script must use posix path and quoted form...which is more complex than the simple Finder duplicate instruction !

Post Status

Asked in February 2016
Viewed 3,264 times
Voted 12
Answered 1 times

Search




Leave an answer