3

enter image description here

I have multiple folders i.e., Fold1_part1 which have 6 subdirectories in them. In each of them has 3 folders full of images labelled either 0,5,10. I am trying to move them to another folder which will hold all the images for each category(3 folders which are 0, 5 or 10).

  • 1
    Welcome to Ask Different! What have you tried already that didn't work (so people don't recommend steps that you've already done)? – fsb Aug 12 at 11:57
6

In Terminal

mkdir -p path/to/target/{0,5,10}
cd path/to/Frames
mv */*/0/* path/to/target/0/
mv */*/5/* path/to/target/5/
mv */*/10/* path/to/target/10/

PS: Use mv -i to get prompted in case of identically named files.

| improve this answer | |
  • 3
    Wow such a simple and easy solution did not know it was possible. – yuRa Aug 12 at 12:37
1

I solved it by writing a python script. Was just looking to see if Finder had any builtin functionality to do it.

EDIT: Added in the code!

import shutil
import os 
import time 
import sys
import concurrent.futures

path_HDD = "/Volumes/HDD/frames/"
path_10 = "/Volumes/HDD/frames_final/10"
path_0 = "/Volumes/HDD/frames_final/0"
path_5 = "/Volumes/HDD/frames_final/5"

def move(path):
    for root, files, directory in os.walk(path, topdown=False):
            if(len(root) == 36 or len(root) == 37):
                if(len(root) == 36 and int(root[-1]) == 0):
                    for r, d, f in os.walk(root, topdown=False):
                        for fi in f:
                            file_path = os.path.join(r, fi)
                            try:
                                shutil.copy(file_path, path_0)
                            except OSError as error:
                                print(error)
                                break
                elif(len(root) == 36 and int(root[-1]) == 5):
                    for r, d, f in os.walk(root, topdown=False):
                        for fi in f:
                            file_path = os.path.join(r, fi)
                            try:
                                shutil.copy(file_path, path_5)
                            except OSError as error:
                                print(error)
                                break
                elif(len(root) == 37 and int(root[-2:]) == 10):
                    for r, d, f in os.walk(root, topdown=False):
                        for fi in f:
                            file_path = os.path.join(r, fi)
                            try:
                                shutil.copy(file_path, path_10)
                            except OSError as error:
                                print(error)
                                break
    print("DONE")
    sys.exit(0)


if __name__ == "__main__":
    try :
        with concurrent.futures.ProcessPoolExecutor():
            move(path_HDD)
    except OSError as error:
        print(error)


| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .