skip to Main Content

I’ve run a batch process to resize and optimize all images within a directory and subdirectories. Unfortunately, Photoshop CC doesn’t have an option (that I’m aware of) to overwrite the existing images and instead creates a ‘JPEG’ directory anywhere it processes images and writes the processed images there. The number of images is relatively large (~2000 images) and they’re divided into hundreds of subdirectories, so manually moving the images to overwrites the existing ones is out of the question.

How can I move all of the processed images in the ‘JPEG’ directories up a level to overwrite the original images? The closes I think I’ve come is this:

find . -type d -name "JPEG" -exec cd {} ; && find . -type f -name "*.jpg" -exec mv -v {} ..  ;

…but that drops all the images a level up from my current directory.

Can some one sort me out?

2

Answers


  1. Your cd only affects a subprocess which changes to the directory and dies, while its parent process remains unaffected.

    Anyway, switching to a directory is rarely necessary or useful; just use the path directly in the mv command.

    find . -type d -name "JPEG" -exec mv -v {}/*.jpg {}/..  ;
    

    (Not in a place where I can test right now, but I guess the wildcard needs a shell, too:

    find . -type d -name "JPEG" -exec sh -c 'mv -v {}/*.jpg {}/..'  ;
    

    Untested, obviously.)

    Login or Signup to reply.
  2. backup your image directory before using the following script.

    CURRENT_DIR=$(pwd)
    for x in $(find -type d -name 'JPEG')
    do
        cd $x && mv -v *.jpg ..  # you can use `cp` instead of `mv`, then remove JPEG directory.
        cd $CURRENT_DIR
    done
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search