Viewing 40 posts - 1 through 40 (of 40 total)
  • DOS batch file or something else?
  • molgrips
    Free Member

    I want to write a utility to go through all the files in a folder (recursively) and use exiftool to extract the rating, then do different operations for different ratings. There’s always two files with the same name and different extension (I shoot JPG and RAW) so for 0 stars, I delete both, 1-3 stars I delete just the RAW, and 4 and 5 I do nothing.

    I’m no good at DOS batch files. I could of course write it in Java but I feel it ought to be a script job not an app.

    GrahamS
    Full Member

    Doesn’t your camera software do this?

    I use (Nikon’s) ViewNX for doing something pretty similar to my photos.

    andrewrchambers
    Free Member

    I’d do that using Bash, but then I use unix…

    If using Windows I’d probably just knock up something in Python quickly.

    molgrips
    Free Member

    I don’t use my camera software, I use PS Elements 8. I wish it would treat RAW and JPG as the same image, but it doesn’t. I think later versions do though.

    Klunk
    Free Member

    python

    molgrips
    Free Member

    Time to learn a new skill then 🙂

    GrahamS
    Full Member

    I don’t use my camera software, I use PS Elements 8.

    yeah I don’t actually edit anything with ViewNX (I use CaptureNX 2, or sometimes Photoshop for that) but I do use it for managing photos cos it can read all the secret squirrel meta-data, does nice full-screen previews for rating/sorting and treats RAW+JPG as one thing.

    It might be worth looking what your own software down – if only just for the workflow aspect.

    DaveyBoyWonder
    Free Member

    perl for loop with a simple if statement. Dead easy… In fact could do that in a batch file as well.

    molgrips
    Free Member

    The Olympus one is paid for I think, although not much, you only get a trial with the camera.. although I could be wrong. PS elements organiser is a bit shite overall but it’s integrated with elements and also premiere, and I have movies on there too.

    My plan was to import everything, browse the catalogue in organiser and rate everything, then run this util to delete the dreck. Then re-open organiser and update.

    geoffj
    Full Member

    Python or PHP

    Cougar
    Full Member

    Offhand, you’d have to recurse through files with a FOR command, call exifdata, depending on how much control you have over its output then maybe pipe its results into FIND, do a bit of string manipulation to isolate the rating, then use the rating in an IF statement to delete the original filename etc accordingly.

    It’s fairly doable I reckon, but there’s almost certainly a dozen better ways of going about it.

    GrahamS
    Full Member

    My plan was to import everything, browse the catalogue in organiser and rate everything, then run this util to delete the dreck. Then re-open organiser and update.

    Can’t you just delete in the organiser??

    My usual approach is
    – go through all the photos full-screen and rate them 0-5
    – change the filter to “0 only”
    – visually check I’ve not accidentally got any good ones there, then Select All and delete.

    That last visual check is why I personally wouldn’t use a script!

    Cougar
    Full Member

    Seems exifdata is written in perl. You could probably modify the perl script directly to add an extra function to do the deleting. (-:

    willard
    Full Member

    Python.

    Or, if like like hurting yourself, Perl.

    TurnerGuy
    Free Member

    learning DOS batch won’t be very satisfying so don’t bother – perl or python, or even java.

    Milkie
    Free Member

    IF you used Adobe Lightroom for cataloging, you can sort by rating and delete all rated at 0. Probably doesn’t help, but Lightroom is worth a look.

    molgrips
    Free Member

    Yeah it’s £££ tho isn’t it? I already ave PSE

    Can’t you just delete in the organiser??

    I can’t automatically transfer ratings from JPG to RAW, which was the step I left out of my original description. PSE doens’t know (in this version) that the RAW and JPG are two files of the same image. Id on’t want to have to go through everything and rate it twice.

    mickyfinn
    Free Member

    If OS = *ix Do Bash
    If OS = Windows Do Powershell

    No point messing with old batch scripting.

    djglover
    Free Member

    This thread made my day

    neville
    Free Member

    You might need the Win32.com client for Python to allow you to access the file attributes.

    TurnerGuy
    Free Member

    sod powershell – learn something useful and transferable…

    python is OO – some of the concepts may help your java programming.

    Learning Java changed some of my C++ style…

    molgrips
    Free Member

    I am going to use exiftool to access the attributes.

    Annoyingly the Photoshop star ratings are not the same as the Windows ones.

    The result of exiftool is something like this:

    Rating: 3

    So I’ll need to get the end of that string to find the rating.

    I’m now thinking about Groovy.. being a Java dev myself it might be easier.

    Milkie
    Free Member

    Sounds like you getting to the limitations of PS Elements. I don’t use it, but can you search for all 1* ratings, then show all jpgs or raws within that search? I know you can do the latter; search for all jpgs by going find>by filename>*.jpg from within PSE.

    brassneck
    Full Member

    PERL is not on Windows by default. Neither is Python. In fact neither is Powershell until relatively recently. But Powershell is the way to go on Windows and it really is pretty damn powerful. I almost like it more than BASH 🙂

    Powershell is a very useful skill to have if you intend to work on Windows servers at all, even 3rd parties like VMWare and NetApp are opening their management tools to scripting via it.

    xiphon
    Free Member

    Powershell is extremely useful – it’s the backbone of Win Vista / Server 2008 onwards.

    TurnerGuy
    Free Member

    Powershell is extremely useful

    yes but molgrips is a java developer, so how much he will use powershell in the future is a consideration. Python might be better to learn as the principles involved may well be useful to him as a dev.

    andrewrchambers
    Free Member

    This isn’t really going to require learning much though… it shouldn’t take long to write a recursive function with an if statement in it no matter what language it’s done in…

    xiphon
    Free Member

    Depends on if he develops Java on a Windows platform….

    That’s like saying, bash isn’t very useful when dev on *nix systems.. 🙄

    molgrips
    Free Member

    Python does come up on job descriptions fairly often, never see n powershell though. Thanks folks, will look at those suggestions. You’d think a for-each for files would be an obvious thing to have in a shell wouldn’t you?

    brungle
    Free Member

    I’d do it in .net but then again thats probably because thats all I really know.
    http://www.microsoft.com/visualstudio/11/en-us/products/express

    you could integrate it into folder context menu (right click), ‘tidy with my new app’ type thing.

    you could go retro and write a VBA macro to do it… (not sure why you would want to!)

    crikey
    Free Member

    You’re all nerds, and I bet the photos are of trains not ladies in undies…

    molgrips
    Free Member

    There’s quite a few pics of two different naked girls in the library.

    crikey
    Free Member

    Your daughters?

    I meant naughty ladies, the kind who trap unwary gentlemen..

    molgrips
    Free Member

    They are pretty naughty at times.

    TurnerGuy
    Free Member

    They are pretty naughty at times.

    you’re doing yourself no favours…

    crikey
    Free Member

    🙂

    poly
    Free Member

    Not tested this but I think it should work in python (poss with some tweaking):

    [Edit – ah bugger doesn’t like my leading spaces… lets try again…]

    Obviously test thoroughly on dummy data or a copy of a folder before trying for real!

    import glob # PROVIDES A NEAT WAY TO HANDLE FOLDERS OF FILES
    import os # NEEDED TO DELETE FILES
    import exiv2 # PROVIDES AN EASY WAY TO ACCESS THE EXIF DATA

    for filename in glob.glob("*.jpg"): # CHANGE TO SUIT

    ~~~~filenameRaw, oldExtn = os.path.splitext(filename)+".raw" # creates filename with new extn

    ~~~~metadata = pyexiv2.ImageMetadata(filename)

    ~~~~metadata.read()

    ~~~~exifStars = metadata['Rating'] # COULD BE 'Exif.Image.Rating' ?

    ~~~~if exifStars==0 :
    ~~~~~~~~os.remove(filename)
    ~~~~~~~~os.remove(filenameRaw)

    ~~~~elif exifStarts<4 :
    ~~~~~~~~os.remove(filenameRaw)

    OK it doesn’t like leading spaced in the code – so you need to replace all the ~ with a space.

    TheBrick
    Free Member

    mickyfinn – Member
    If OS = *ix Do Bash
    If OS = Windows Do Powershell

    No point messing with old batch scripting.

    pfft

    If OS = install cygwin.

    P.S. I presume your best friend is Skibadee?

    forexpipz
    Free Member

    Are you fourteen or something. I’m a mechanical engineer but I’m not going to sound like a complete and utter **** by posting irrelevant Calculus questions on a biking site. Seriously.

    Cougar
    Full Member

    Loving your alternative choice. Far more constructive.

Viewing 40 posts - 1 through 40 (of 40 total)

The topic ‘DOS batch file or something else?’ is closed to new replies.