1

I'm importing files into a DAM, both RAW files and edited JPG's. Both file types are supposed to have the same file name, but I've run into a couple folders where the DNG's have serial file names (IMG_01.dmg, IMG_02.dmg, IMG_03.dmg, etc...), but the edited JPG's were exported with the names of the models as their filenames (FirstLastname_01.jpg, FirstnameLast_02.jpg, LastnameFirstname_03.jpg, etc...) What's fortunate is that the sequence number matches on both the raw and exported filetypes. What I want to know is if there's a way I can use the sequence numbers to batch rename all the raw file types to match the filenames of the jpegs.

Has anyone done anything like this before? Are there any apps that can do this task? I'm hoping to figure out how to do this with Adobe Bridge.

2
  • I suggest that you learn python (or similar language) and write a short script for this task. Aug 12, 2015 at 8:43
  • This belongs on SuperUser but too old to migrate now
    – Ryan
    Nov 10, 2015 at 13:48

1 Answer 1

0

And the operating system is ...?

 for file in *dmg
 do
    nrdmg=${file/*_/}
    nr=${nrdmg/.*/}
    name=*_$nr.jpg
    bn=$(basename $name .jpg);
    echo mv $file $bn.dmg 
 done

If that looks good, remove the "echo". This will work out of the box on a unixiod system with bash as shell, i.e. Linux, maybe MacOS.

There is a free sh-Implementation for Windows systems too. With WindowsPowderShell or command(32?64?).exe, similar commands should be possible, but I would expect a diffrent syntax.

If your files are in sequence, say from IMG_17.dmg to IMG_49.dmg, it would be even simpler:

for n in {17..49}; do jpg=*$n.jpg ; base=$(basename $jpg .jpg); echo mv IMG_$n.dmg $base.dmg; done

(Again the 'echo' is for first controlling.)

Note that on unixoid systems, the case of the names (JPG/jpg etc.) matters.

Second note: For leading zeros, you have to write them down:

for n in {01..09}; do jpg=*$n.jpg ; base=$(basename $jpg .jpg); echo mv IMG_$n.dmg $base.dmg; done
5
  • You should put the variables in double quotes to accommodate file names containing shell metacharacters, including whitespace. So mv "$file" "$bn.dmg" etc.
    – tripleee
    Oct 20, 2016 at 5:56
  • The basename on a wildcard is risky for other reasons -- you cannot quote the wildcard there, which means it could expand to more than one match, which will produce a syntax error from basename when it receives more parameters than it accepts.
    – tripleee
    Oct 20, 2016 at 5:58
  • @tripleee: From the example presented in the question, there is no hint for a whitespace, but of course you're free to add them though. And of course you should always test - that's why I added the test with echo. For the second comment - can you give an example? Oct 20, 2016 at 23:46
  • A production script should work with any file name, not just the file names in the example given; way too many scripts - even from respected projects - fail with file names with nontrivial names. The wildcard would fail if the input was IMG_02.jpg and there were other files with the same suffix, so e.g. image_02.jpg and thumbnail_02_02.jpg in the same directory (basename *_02.jpgwould get expanded to basename IMG_02.jpg image_02.jpg thumbnail_02_02.jpg by the shell).
    – tripleee
    Oct 21, 2016 at 3:29
  • @tripleee: Well, I never promised a production script. The question clearly talks only about serial filenames. If you don't operate on copies in a new directory, you are always very vulnerable to errors, bad intend, bad jokes or sloppy assumptions. Nonetheless, my test with echo shows the problem with image_02.jpg and thumbnail_02_02.jpg. Oct 21, 2016 at 20:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.