How do i extract files from folders??

Joined
Apr 22, 2013
Messages
1
Reaction score
0
Points
1
Hi
I have close to 1000 folders with close to 5000 files. Is there a way to extract all files without going to each folder and extracting them to a root folder individually?

This is several days of work that I dont want to do....

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
Welcome to Mac-Forums.

Unless you have compressed files here, what you are talking about is not extracting, but rather copying files..

You will probably not be able to do what you want from the UI or Finder, but rather through a shell script or something..

For example, assume you have 10 directories with 10 files (named the same to make it complicated) like this:
.:
one two three four five six seven eight nine ten

./one:
fileOne fileTwo fileThree fileFour fileFive fileSix fileSeven fileEight fileNine fileTen

./two:
fileOne fileTwo fileThree fileFour fileFive fileSix fileSeven fileEight fileNine fileTen

./three:
fileOne fileTwo fileThree fileFour fileFive fileSix fileSeven fileEight fileNine fileTen

./four:
fileOne fileTwo fileThree fileFour fileFive fileSix fileSeven fileEight fileNine fileTen

./five:
fileOne fileTwo fileThree fileFour fileFive fileSix fileSeven fileEight fileNine fileTen

./six:
fileOne fileTwo fileThree fileFour fileFive fileSix fileSeven fileEight fileNine fileTen

./seven:
fileOne fileTwo fileThree fileFour fileFive fileSix fileSeven fileEight fileNine fileTen

./eight:
fileOne fileTwo fileThree fileFour fileFive fileSix fileSeven fileEight fileNine fileTen

./nine:
fileOne fileTwo fileThree fileFour fileFive fileSix fileSeven fileEight fileNine fileTen

.ten:
fileOne fileTwo fileThree fileFour fileFive fileSix fileSeven fileEight fileNine fileTen

You first get a list of all the files with:
Code:
find . -type f > file.list

Now this script will iterate over each of the files and copy them to the local (root) directory by prefixing the directory name to each file so you know where it came from. I'm only dealing with files one level deep, if you have files that are multi-directory deep, you'll have to modify the script accordingly..

Code:
for file in `cat file.list`; 
do d=`echo $file | sed -e 's/\// /g'`; 
dir=`echo $d | awk '{print $2}'`; 
f=`echo $d | awk '{print $3}'`; 
echo "Moving $file to $dir-$f"; 
mv $file $dir-$f; 
done

You might have to not add the "mv $file $dir-$f" portion of the script and just see what the echo is going to show you to ensure that the files are being moved properly..

Also, you might want to play around with this script in a separate test folder until you're sure it's doing what you want before running it on the real folders..
 

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