While I’m not entirely new to Applescript, it’s been years since I’ve been into it, and I’m on the verge of a head explosion trying to write a script… any help would be appreciated.
I have one folder with hundreds of nested folders and another one with identically named folders (it’s music sample related- one has program data and the other is sample data).
The application I’m working with requires the identically named samples folder to be nested inside it’s program folder parent. (And when I say I have “one” folder, that’s just for example. In fact, I have about 50 such instances, so we’re talking over 10,000 moves I’d have to make manually.)
So, I’m trying to write a script that will look at my selected parent folder and move all nested folders inside into their identically named folders in another parent folder. I hope that’s clear!!
I’m able to extract the path for a given folder, but I’m having a hard time extrapolating the similarly named destination at a different path.
Again, I’d be so grateful for any help with this!
thanks,
Andy
Model: Power PC G5
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.5)
set theSource to choose folder with prompt "Please select the source folder"
set theTarget to (choose folder with prompt "Please select the destination folder") as Unicode text
tell application "Finder"
set sourceFolders to folders of theSource
repeat with aFolder in sourceFolders
move aFolder to folder (theTarget & (name of aFolder))
end repeat
end tell
Or if your intent was to move only the files (not their parent folder) then this, perhaps:
-- Script to illustrate one method; by no means optimized -- left linear for clarity.
set P to alias ((path to desktop as text) & "Parent")
set N to alias ((path to desktop as text) & "Nest")
tell application "Finder"
set NFP to {} -- Name of Parent Folders
set NFF to {} -- Path to Parent Files
set NFN to {} -- Name of Target Folders
-- get the parent set of folders
set FP to folders of P as alias list
-- then the names and files they contain
repeat with oneF in FP
set end of NFP to name of oneF
set end of NFF to files of oneF as alias list
end repeat
-- get the target set of folders
set FN to folders of N as alias list
-- get their names
repeat with oneF in FN
set end of NFN to name of oneF
end repeat
-- now find the appropriate targets and move them
repeat with k from 1 to count NFP
set aName to item k of NFP
-- find this name in the target folder
repeat with j from 1 to count NFN
if item j of NFN is aName then
move item k of NFF to item j of FN
exit repeat
end if
end repeat
end repeat
end tell