skip to Main Content

I’ve got a bunch of subdirectories with a couple thousand PNG files that will be sent through Photoshop, creating PSD files. Photoshop can only output those to a single folder, and I want to move each one back to their original directory – so the new file foo_bar_0005.psd should go to where foo_bar_0005.png already is. Every filename only exists once.

Can somebody help me with this? I’m on OSX.

2

Answers


  1. Each file found with this find is piped to a Bash command that successively make the psd conversion and move the .psd to the .png original directory.

    psd_dir=/psd_dir/
    export psd_dir
    
    find . -type f -name '*.png' | xargs -L 1 bash -c 'n=${1##*/}; echo photoshop "$1" && echo mv ${psd_dir}${n%.png}.psd ${1%/*}/; echo' ;
    

    The echo are here to give you an overview of the result.

    You should remove them to launch the real photoshop command.

    Login or Signup to reply.
  2. You might start from this minimal script:

    #!/bin/bash
    
    search_dir="search/png/from/this/directory/"
    psd_dir="path/to/psd/directory/"
    
    for psd_file in "$psd_dir"*.psd; do
        file_name="$(echo $psd_file | sed 's/.*/(.*).psd$/1/g')"
        png_dir="$(find $search_dir -name $file_name.png | grep -e '.*/' -o)"
        mv $psd_file $png_dir
    done
    

    But note that this script doesn’t include any error handlers e.g. file collision issue, file not found issue, etc.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search