Auto save files from folder structure?

Discussion in 'Mac Basics and Help' started by pavvel, Jul 27, 2015.

  1. pavvel macrumors member

    Joined:
    Jul 18, 2013
    #1
    Hi guys,

    Bit of a long shot but wondering if someone can help.

    I have backed up my iMessage attachment folder with a whole load of pictures. I would like to save these pictures into one folder but as you may know it lays them out in a sub>sub>sub type folder for each picture. Is there anyway or any app that lets you grab the file out of the parent folders and sub folders and put them into one? There is so many by hand this would take forever.

    Thanks.
     
  2. Toutou macrumors 6502a

    Toutou

    Joined:
    Jan 6, 2015
    Location:
    Prague, Czech Republic
    #2
    If you don't mind using bash commands, here you go:

    Open Terminal, type "cd", then a SPACE, then drag&drop your folder from Finder, so it looks like this:
    Code:
    cd /Your/backup/folder
    press enter, this will change your working directory to the one you specified. Then copy&paste this:
    Code:
    mkdir FILES; find . -type f -exec cp {} ./FILES/ ";"
    and press enter, this will find any FILES (type f) in your working directory (.) and any subfolders and copy them (cp {}) into a folder named FILES.

    Tested and works.
     
  3. pavvel thread starter macrumors member

    Joined:
    Jul 18, 2013
    #3
    Thank you for the reply. Where will the folder FILES end up so I can see the result?
     
  4. pavvel thread starter macrumors member

    Joined:
    Jul 18, 2013
    #4
    Forget that I worked it out. What if the file names are the same and when they are pulled into the same folder they don't copy. Is there anyway around this?
     
  5. Toutou, Jul 27, 2015
    Last edited: Jul 27, 2015

    Toutou macrumors 6502a

    Toutou

    Joined:
    Jan 6, 2015
    Location:
    Prague, Czech Republic
    #5
    Maybe, try using this instead of the second one:

    Code:
    mkdir FILES; find . -type f >> temp;
    for file in `cat temp`;
    do filenew="$file";
    cp -n "$file" ./FILES/;
    if [ $? -eq 1 ] ; then
    filenew="$file"`md5 $file | cut -d'=' -f2`;
    cp -n "$file" "./FILES/${filenew##*/}";
    fi;
    done;
    rm -r temp;
    I guarantee nothing, btw :D

    Edit: What I did is i told the script to append a MD5 checksum to the filename if the copy command tries to overwrite a file with the same filename. It took me an hour :D I do need to brush up on my bash skills.
     
  6. pavvel thread starter macrumors member

    Joined:
    Jul 18, 2013
  7. Toutou macrumors 6502a

    Toutou

    Joined:
    Jan 6, 2015
    Location:
    Prague, Czech Republic
    #7
    ...well...... or you could just import the folder into Photos, then Select All and export into a folder :D
     

Share This Page