Moving multiple files from multiple folders into one

Joined
Jun 1, 2015
Messages
2
Reaction score
0
Points
1
Found this forum while googling for my question, which I can't really find an answer for. I'm just trying to find out how I can use Apple Script Editor (or anything else) to move multiple files into one folder. I have a folder containing about 900 images and their corresponding text files which, after downloading, are each contained within an individual folder inside the first folder (so one image file and one text file per folder x 900.) I want to get these individual files out of their individual folders and have all 900 image files plus the 900 corresponding text files in one single folder, so I can look at all of the images at once. What is the correct script for doing this? I tried:

tell application "Finder"

move (every file of every folder of window 1) to (get target of window 1)

end tell

That's something someone on another forum suggested, but I'm getting error signs. Let's say my original folder containing the images is called "Single Images" and the folder I want to move them to is called "Single Images 2." Both folders are on the desktop. What is the right command to do this? Or is there another application that can do this more easily if Apple Script Editor isn't the right one?

Any help appreciated, it would save me hours of dragging and dropping if I can find the right command.

Thanks!
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,762
Reaction score
2,100
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
You can do this fairly easily from the terminal.

Assuming your directory structure is something like:
drwxr-xr-x 4 <username> staff 136 Jun 1 09:01 five
drwxr-xr-x 4 <username> staff 136 Jun 1 09:01 four
drwxr-xr-x 4 <username> staff 136 Jun 1 09:01 one
drwxr-xr-x 4 <username> staff 136 Jun 1 09:01 three
drwxr-xr-x 4 <username> staff 136 Jun 1 09:01 two

./five:
total 0
-rw-r--r-- 1 <username> staff 0 Jun 1 09:01 five.img
-rw-r--r-- 1 <username> staff 0 Jun 1 09:01 five.txt

./four:
total 0
-rw-r--r-- 1 <username> staff 0 Jun 1 09:01 four.img
-rw-r--r-- 1 <username> staff 0 Jun 1 09:01 four.txt

./one:
total 0
-rw-r--r-- 1 <username> staff 0 Jun 1 09:01 one.img
-rw-r--r-- 1 <username> staff 0 Jun 1 09:01 one.txt

./target:

./three:
total 0
-rw-r--r-- 1 <username> staff 0 Jun 1 09:01 three.img
-rw-r--r-- 1 <username> staff 0 Jun 1 09:01 three.txt

./two:
total 0
-rw-r--r-- 1 <username> staff 0 Jun 1 09:01 two.img
-rw-r--r-- 1 <username> staff 0 Jun 1 09:01 two.txt

Then the following BASH script will copy all the files to a single folder elsewhere.

Code:
for dir in `ls`; do cp $dir/* [B]../target[/B]; done

The bolded piece above is the target folder you want to send all the files to.
 
OP
Q
Joined
Jun 1, 2015
Messages
2
Reaction score
0
Points
1
Thanks a lot for the reply!

I haven't really used Terminal before and I'm not quite sure how to find out if my directory structure looks as shown above. Where can I find this?

So, if I give in that code, I would substitute the word "target" with the name of the folder I want the files to be moved into? What about the name of the folder the files and subfiles are in now, do I have to write its name anywhere? Or maybe just open it in Finder before I write the script?

Sorry for the dumb questions, but I've never done this before and am worried I'll do something wrong. Can I undo it if I screw up somewhere?

I really need this for a computer I'm using at work, which runs Yosemite, but I want to try it out on a sample folder I created on my own computer, just to see if I can get it to work. That one runs Snow Leopard. Not sure if there is a difference in terms of what to write.

Thanks so much for the help!
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,762
Reaction score
2,100
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
With both Terminal and Finder windows open, you can easily go to the right folder. In Finder, first go to the top level folder that contains your directory structure that you want to copy files from. Then in the terminal, enter the command 'cd'. Now look at the bottom of the Finder window and you'll see the path, grab the last folder, left-click and drag it to the Terminal window and you will now have a path after the 'cd' command. Hit the RET key to go to that folder.

Type "ls -l" to see the directory structure and "ls <folder name>" to see the contents. If they match what I have above, then my script will work. If the structure is different, then the script will have to be updated.

You don't need to enter each folder name, the use of the `ls` command in the script ensures that you get them for free.

The target folder is indeed the single folder that will contains all of your data. You should put it in some other location and ensure that you create the folder first before doing the copy.

To make the command failsafe, add the "-i" argument to "cp" to make it an interactive copy. That means that it will ask you for every single copy if you wish to proceed. If you don't like what you are seeing, hit CTRL-C to break out of the entire thing.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top