Copy file from one folder to a modified version of the original path?

Is this possible? I have files in multiple folders on a server. I need copies of the files copied to other folders on the server. However, heres the tricky part- the new folder paths are based on the paths of the original location. For example- File1.jpg is in Server1/Folder1/Subfolder1 /Subsubfolder1 and it needs to be copied to Server1/Folder2/Subfolder1/Subsubfolder1

So only a slight change exists in the new path, AND if the new path doesn’t exist, it’d be great to be able to get a warning dialogue box and then an option to either stop there or create the new folders.

Any help would be much appreciated!

Hi,

try this, the intermediate directories will be created automatically


property folder2 : "Folder2"

set sourceFile to POSIX path of (choose file)
set TID to text item delimiters
set text item delimiters to "/"
tell text items of sourceFile to set destinationFile to ({items 1 thru 2} & folder2 & items 4 thru -1) as text
set text item delimiters to TID
do shell script "/usr/bin/ditto " & quoted form of sourceFile & space & quoted form of destinationFile

Hi, thanks for the reply… follow up question (sorry for being a newbie)…

If I wanted to use a “find and replace” method instead, is that possible? For example, if I chose a file with the path:

/Volumes/Server1/Art/People/Original/Men/man.jpg

and wanted it copied to:

/Volumes/Server1/Art/People/Retouched/Men/

Is there a way to always find the word “Original” in a path and replace it with “Retouched” instead for the new location?

Thanks again!


property folder1 : "Original"
property folder2 : "Retouched"

set sourceFile to POSIX path of (choose file)
set TID to text item delimiters
set text item delimiters to folder1
set t to text items of sourceFile
set text item delimiters to folder2
set destinationFile to t as text
set text item delimiters to TID
do shell script "/usr/bin/ditto " & quoted form of sourceFile & space & quoted form of destinationFile

Thank You! Works like a charm!