Folder extractor/merger?

Joined
Mar 2, 2021
Messages
13
Reaction score
0
Points
1
Is there any tool that can merge the contents of different folders into a single folder?

example:
CleanShot 2022-05-02 at 16.53.54.png
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
16,082
Reaction score
2,508
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Here is what I did, created a folder called source that has your structure and dest is where I want all the files.

I started with:

./source
./source/fol1
./source/fol1/file1.txt
./source/fol2
./source/fol2/file2.txt
./source/fol3
./source/fol3/file3.txt
./source/fol3/subfol
./source/fol3/subfol/subfile.txt
./dest

I then ran the following command in the Terminal
Code:
find source -type f -exec cp {} dest \;

You'll want to change the source and dest folder as you see fit.

Now I have the following

./source
./source/fol1
./source/fol1/file1.txt
./source/fol2
./source/fol2/file2.txt
./source/fol3
./source/fol3/file3.txt
./source/fol3/subfol
./source/fol3/subfol/subfile.txt
./dest
./dest/file2.txt
./dest/file3.txt
./dest/file1.txt
./dest/subfile.txt

If you are not comfortable with the command line, please first validate what you are going to do and I can tell you if your command is right or wrong.
 
OP
P
Joined
Mar 2, 2021
Messages
13
Reaction score
0
Points
1
Here is what I did, created a folder called source that has your structure and dest is where I want all the files.

I started with:



I then ran the following command in the Terminal
Code:
find source -type f -exec cp {} dest \;

You'll want to change the source and dest folder as you see fit.

Now I have the following



If you are not comfortable with the command line, please first validate what you are going to do and I can tell you if your command is right or wrong.
its partially correct, your output contains only files and not the subfolders in each folder.

I want to select the folders a,b,c or the "src" folder and merge them into a new destination folder.
If a file exists in the destination folder it should replace it with the new file
In the example below, the 1.txt file from folder "a" contains old data and should be replaced with the 1.txt file from folder "c".

PS: By "new file" i dont mean new in terms of date, but new in terms of the order that each folder gets read to process the merging. If the selection of folders was not "a,b,c" but "c,b,a" the final 1.txt file should contain the data of the "a" folder.

Here is a real example on mac
CleanShot 2022-05-02 at 22.38.52.png
 

krs


Joined
Sep 16, 2008
Messages
3,574
Reaction score
618
Points
113
Location
Canada
Is there any tool that can merge the contents of different folders into a single folder?

a windows tool that works perfectly for me is: 2XDSOFT - Folder Merger
I'm obviously missing some important detail......

I just merged two folders on my Mac.

Opened one which had a long list of video files and also embedded folders.
Did a "Select All" and dragged the selected items to the folder I wanted the files and folders to merge with.
If the file or folder already existed on the target folder I would get an option to either replace the file/folder I'm moving or to skip.
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
16,082
Reaction score
2,508
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Assuming that you've named the folders in a way through which find gives you the correct order, just adding "-f" to the cp command will ensure that the same file found later on will replace the already existing/copied file.

So the 1.txt from c will overwrite the previously copied over 1.txt from a in that case.

The limitation of this command is that you lose any subfolders and their structure, you will just get a flat list of files. There are ways to control that of course with a script and arguments to find..

Let me see what I can do..
 
OP
P
Joined
Mar 2, 2021
Messages
13
Reaction score
0
Points
1
I'm obviously missing some important detail......

I just merged two folders on my Mac.

Opened one which had a long list of video files and also embedded folders.
Did a "Select All" and dragged the selected items to the folder I wanted the files and folders to merge with.
If the file or folder already existed on the target folder I would get an option to either replace the file/folder I'm moving or to skip.
yes , but how do you do that in a quick way when you have 100 folders to merge?

the ideal would be to select all those 100 folders , define the destination folder and it will copy/merge in the destination folder in a serial way, so it ALWAYS overwrites the existing file
 

krs


Joined
Sep 16, 2008
Messages
3,574
Reaction score
618
Points
113
Location
Canada
yes , but how do you do that in a quick way when you have 100 folders to merge?

the ideal would be to select all those 100 folders , define the destination folder and it will copy/merge in the destination folder in a serial way, so it ALWAYS overwrites the existing file
You get that option.
When the software detects a file/folder that already exists in the target folder, you can chose replace or skip and the also select to apply this to all files/folders being moved.
Just to be clear - I'm just talking about drag and drop, ie 'Select All", grab the highlighted items n drag & drop them to the folder where you want them.
I had several hundred videos, one batch on a 750GB external and another several hundred video files in a volume on another external - I movedall of them to a 2TB external eliminating all duplicates in the process.
I would suggest you try that on a small test sample.
 
Last edited:

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,982
Reaction score
1,396
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Sequoia, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
There re several of these kinds of apps in the App Store. Right nowI have Folder Sync Pro installed but there are numerous others. IIRC some of them have the option for In App Purchases that add additional features.
 
OP
P
Joined
Mar 2, 2021
Messages
13
Reaction score
0
Points
1
You get that option.
When the software detects a file/folder that already exists in the target folder, you can chose replace or skip and the also select to apply this to all files/folders being moved.
Just to be clear - I'm just talking about drag and drop, ie 'Select All", grab the highlighted items n drag & drop them to the folder where you want them.
I had several hundred videos, one batch on a 750GB external and another several hundred video files in a volume on another external - I movedall of them to a 2TB external eliminating all duplicates in the process.
I would suggest you try that on a small test sample.
Yes, but it would also copy/paste the selected folder, i just want to select multiple folders and copy the contents of those folders (inner subfolders and files) not the actual selected folder
 

krs


Joined
Sep 16, 2008
Messages
3,574
Reaction score
618
Points
113
Location
Canada
Yes, but it would also copy/paste the selected folder, i just want to select multiple folders and copy the contents of those folders (inner subfolders and files) not the actual selected folder
I don't understand the problem.
You just select the files and folders that you actually want to copy (really move), if there are folders where you want to copy/paste the content, just open the folder and select the items you want.
And it's not actually copy/paste - you just grab the selected items, drag them to the folder where you want them and drop them in there.
Another option is to drag & drop the whole folder, then go to the new loation and open that folder by clicking on the little arrow just to the left of the folder name.
That will show the folder content in list view and you can just drag all items to the original target folder (that this folder is part of) and then delete the folder that you had moved (which now is empty).
If you make a mistake - say you dragged and dropped in the wrong folder, just use Edit > Undo and try again
 
OP
P
Joined
Mar 2, 2021
Messages
13
Reaction score
0
Points
1
each folder in the screenshot below contain multiple subfolders and files, and I can have hundreds of those folders, manually selecting the content of each folder to copy/paste is not time efficient.

I need a tool where I can select all these folders and copy/paste the content of each folder in a new destination, and if an existing file is found, it should replace it, and if an existing subfolder is found it should merge it.
The windows tool i have provided does the job perfectly, but on Mac i still havent found a solution.



CleanShot 2022-05-03 at 17.10.07.png
 
OP
P
Joined
Mar 2, 2021
Messages
13
Reaction score
0
Points
1
I have solved the above issue, with the following commands on terminal
source_folder contains folders like the ones in the screenshot above
Code:
cd source_folder
cp -r -p */* ../destination_folder

My question now is, how does */* fetch folders exactly? according to my tests it works like it goes to each folder in a serial way sorted by name? can we confirm that somehow
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
16,082
Reaction score
2,508
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
"-r" is recursive, "-p" is preserve. * is everything. So you are tell the 'cp' command to recursively go through everything in the current folder and everything in a sub-folder and copy it to the destination folder without changing anything.

With the '-r' option, you don't need the */*, just a * is sufficient since it will just keep going down to the lowest level sub-folder.
 
Joined
Sep 30, 2007
Messages
9,962
Reaction score
1,236
Points
113
Location
The Republic of Neptune
Your Mac's Specs
2019 iMac 27"; 2020 M1 MacBook Air; macOS up-to-date... always.
Ok, here's a crazy idea I worked out. Assuming all these folders are located under a single master folder..... using Find Any File, search for the contents of that master folder. Add these as the parameters:

File size is greater than 0
is a folder set to No.

Now click on Find. You'll get a new window with all the contents of the master folder whose file sizes are greater than 0 (i.e. everything) and otherwise are not a folder. If you want to be certain... add another parameter where File size is equal to 0 also.

In your search results, press COMMAND-A to select everything. Now, you can simply drag everything from that results window to a Finder folder of your choice. Now, this will include a bunch of hidden files like .DS_Store, of which you'll have multiple hits (one for each folder). You can either de-select those before doing the move, or add another search parameter to skip hidden files.
 

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