Apple Intelligence is now available on iPhone, iPad, and Mac!

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How can I copy directories listed in a file?

Hopefully, someone knows the answer to this one: how can I copy folders listed in a file? The list contains the full pathnames of the folders. The folders need to be copied from one location to another. Thanks in advance.

Posted on May 7, 2022 4:18 AM

Reply
Question marked as Top-ranking reply

Posted on May 7, 2022 8:41 AM

I have my Synology DiskStation share mounted on my Desktop as share. In that share folder is my Viking user folder. On my Desktop is a file named folders.txt, which I have placed a single entry, where the tilde is just shorthand for my home directory, but in your case, multiple folders would still work.


folders.txt

~/Desktop/TestX/Work


Terminal commands

cd ~/Desktop
cp -a $(cat folders.txt) /Volumes/share/Viking


and the result (using the free, third-party tree cmd:




10 replies
Question marked as Top-ranking reply

May 7, 2022 8:41 AM in response to Thomoos

I have my Synology DiskStation share mounted on my Desktop as share. In that share folder is my Viking user folder. On my Desktop is a file named folders.txt, which I have placed a single entry, where the tilde is just shorthand for my home directory, but in your case, multiple folders would still work.


folders.txt

~/Desktop/TestX/Work


Terminal commands

cd ~/Desktop
cp -a $(cat folders.txt) /Volumes/share/Viking


and the result (using the free, third-party tree cmd:




May 7, 2022 4:42 AM in response to Thomoos

Thomoos wrote:

Hopefully, someone knows the answer to this one: how can I copy folders listed in a file? The list contains the full pathnames of the folders. The folders need to be copied from one location to another. Thanks in advance.

Q -" how can I copy folders listed in a file "


A - What type of FILE is this ?


A - Is it a TextEdit or some other type of text based file ?

May 7, 2022 5:41 AM in response to Thomoos

The Finder has no clue how to map a list of text file folder paths into a move or copy operation unless one writes some AppleScript. It can be done in the Terminal application with a single command and (some common sense about source and destination content).


Are the source folders and destination folder both on your Mac, or the one or both on a drive mounted to your Mac? Do any of those folders in your list contain a sub-folder hierarchy and do you have the available storage to effect that en masse folder copy without exhausting local storage?

May 7, 2022 6:49 AM in response to VikingOSX

Hi, VikingOSX,


Ab AppleScript: would be great .However, I don't have the skills to write one. Actually, I was thinking about a shell script. Unfortunately I don't possess the skills to do that either.


Source folders: on my Mac.

Destination folder: on a Synology NAS, connected via LAN to my Mac.


Sub-folder hierarchy: yes, and I will create an extra folder to contain the copied folders.a


Available storage without exhausting local storage: yep, checked that already

May 7, 2022 11:39 AM in response to VikingOSX

Hi VikingOSX, I tested your solution on a small scale, and it worked great. I'm still working on the contents of the TXT file containing the folder names. The command I gave was:

find . -name "*.jpg" > list.txt

What I needed was a list of all folders containing one or more .jpg files. Maybe I should pipe it to grep or fgrep to strip the file names, bet I'm not familiar with that.


Anyway, you solved the problem I posted. Many thanks!

How can I copy directories listed in a file?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.