assuming the paths in the text file are full paths you could use this
set destinationFolder to POSIX path of (choose folder)
set theDirectories to paragraphs of (read file "disk:path:to:file.txt")
repeat with oneDirectory in theDirectories
do shell script "/usr/bin/ditto " & quoted form of oneDirectory & space & quoted form of destinationFolder
end repeat
Thanks for your rapid reply, I’ve tried to run your script, to no avail.
To be clear: what is the purpose of the folder being requested? Is this the destination folder for the list of directories to copy? And if so, how do I specify the .txt file which contains the list to be copied?
-- diskname:subfolders:filename
set v to alias "Macintosh HD:users:username:desktop:afile.txt"
-- or
set v to (((path to desktop) as text) & "afile.txt")
-- or
set v to (choose file)
Ok, progress…of a sort. Here’s how I’ve modified your script:
set destinationFolder to POSIX path of (choose folder)
set theDirectories to paragraphs of (read alias "Macintosh HD:Users:glenn:Desktop:apeonlydirs_v1.0.txt")
repeat with oneDirectory in theDirectories
do shell script "/usr/bin/ditto " & quoted form of oneDirectory & space & quoted form of destinationFolder
end repeat
Now I manage to get to the command line ‘repeat with…,’ only to get error message:
error “ditto: can’t get real path for source” number 1.
The file ‘apeonlydirs_v1.0.txt’ looks like this:
/Volumes/media/Music/MC\ Files/Ape/Alanis Morissette/Jagged Little Pill
/Volumes/media/Music/MC\ Files/Ape/Andrew Hill
/Volumes/media/Music/MC\ Files/Ape/Andrew Hill/Point of Departure
/Volumes/media/Music/MC\ Files/Ape/Andrew Lloyd Webber
/Volumes/media/Music/MC\ Files/Ape/Andrew Lloyd Webber/Highlights from The Phantom of The Opera
/Volumes/media/Music/MC\ Files/Ape/B-Tribe
/Volumes/media/Music/MC\ Files/Ape/B-Tribe/Fiesta Fatal!
…where the directory paths were lifted from the Finder (files stored on a remote NAS), where media is a mounted share. Do I need to list the explicit path? The share was mounted using AFP
If your path all ready has the '' before every space, I think getting rid of the quoted form of will make your script work:
set destinationFolder to POSIX path of (choose folder)
set theDirectories to paragraphs of (read alias "Macintosh HD:Users:glenn:Desktop:apeonlydirs_v1.0.txt")
repeat with oneDirectory in theDirectories
do shell script "/usr/bin/ditto " & oneDirectory & space & quoted form of destinationFolder
end repeat
Update - Figured it out with a bit of sleuthing…seems to work ok now, thanks!
One or two follow on questions if I might:
i) What if I wanted to create a subdirectory similar to the subdirectories listed in the input file?
EG, If the target directory is “./Files_to_Convert”
and my input file contains the following subdirectories:
…
/Volumes/media/Music/MC Files/Ape/Counting Crows/August and Everything After
/Volumes/media/Music/MC Files/Ape/Cowboy Junkies/Black Eyed Man
…
your script currently dumps all files within these subdirectories into “./Files_to_Convert”
How can I put them into the corresponding subdirectories:
…
./Files_to_Convert/Counting Crows/August and Everything After
./Files_to_Convert/Cowboy Junkies/Black Eyed Man
…
?
Also
ii) is there anyway to skip copying a folder if it contains subfolders?
Eg, if there are two lines in the input file
‘./Cowboy Junkies’
‘./Cowboy Junkies/Black Eyed Man’
can the script ignore the first instance? (The file is the product of a recursive find, and includes some parent directories under the grandparent which is really just an organizing folder).
It does! One question - occasionally, my input file specifies a non existent directory (dunno how it happened!), and I get message “ditto: can’t get real path for source.” How can I prevent the script from stopping upon getting this message, and move onto the next line?