DOS batch file or s...
 

MegaSack DRAW - This year's winner is user - rgwb
We will be in touch

[Closed] DOS batch file or something else?

39 Posts
20 Users
0 Reactions
77 Views
Posts: 91097
Free Member
Topic starter
 

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.


 
Posted : 06/09/2012 12:59 pm
Posts: 31206
Full Member
 

Doesn't your camera software do this?

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


 
Posted : 06/09/2012 1:04 pm
Posts: 0
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.


 
Posted : 06/09/2012 1:05 pm
Posts: 91097
Free Member
Topic starter
 

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.


 
Posted : 06/09/2012 1:08 pm
Posts: 11402
Free Member
 

python


 
Posted : 06/09/2012 1:09 pm
Posts: 91097
Free Member
Topic starter
 

Time to learn a new skill then 🙂


 
Posted : 06/09/2012 1:11 pm
Posts: 31206
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.


 
Posted : 06/09/2012 1:13 pm
Posts: 8839
Free Member
 

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


 
Posted : 06/09/2012 1:22 pm
Posts: 91097
Free Member
Topic starter
 

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.


 
Posted : 06/09/2012 1:22 pm
Posts: 0
Full Member
 

Python or PHP


 
Posted : 06/09/2012 1:28 pm
Posts: 77691
Free 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.


 
Posted : 06/09/2012 1:30 pm
Posts: 31206
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!


 
Posted : 06/09/2012 1:31 pm
Posts: 77691
Free Member
 

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


 
Posted : 06/09/2012 1:32 pm
Posts: 8934
Full Member
 

Python.

Or, if like like hurting yourself, Perl.


 
Posted : 06/09/2012 1:33 pm
Posts: 0
Free Member
 

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


 
Posted : 06/09/2012 1:37 pm
Posts: 0
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.


 
Posted : 06/09/2012 1:42 pm
Posts: 91097
Free Member
Topic starter
 

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.


 
Posted : 06/09/2012 1:45 pm
Posts: 0
Free Member
 

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

No point messing with old batch scripting.


 
Posted : 06/09/2012 1:47 pm
Posts: 145
Free Member
 

This thread made my day


 
Posted : 06/09/2012 1:52 pm
Posts: 0
Free Member
 

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


 
Posted : 06/09/2012 1:54 pm
Posts: 0
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...


 
Posted : 06/09/2012 1:57 pm
Posts: 91097
Free Member
Topic starter
 

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.


 
Posted : 06/09/2012 2:00 pm
Posts: 0
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.


 
Posted : 06/09/2012 2:04 pm
Posts: 0
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.


 
Posted : 06/09/2012 2:07 pm
Posts: 0
Free Member
 

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


 
Posted : 06/09/2012 2:08 pm
Posts: 0
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.


 
Posted : 06/09/2012 2:53 pm
Posts: 0
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...


 
Posted : 06/09/2012 3:14 pm
Posts: 0
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.. 🙄


 
Posted : 06/09/2012 3:25 pm
Posts: 91097
Free Member
Topic starter
 

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?


 
Posted : 06/09/2012 3:37 pm
Posts: 0
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!)


 
Posted : 06/09/2012 3:41 pm
Posts: 0
Free Member
 

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


 
Posted : 06/09/2012 3:45 pm
Posts: 91097
Free Member
Topic starter
 

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


 
Posted : 06/09/2012 3:50 pm
Posts: 0
Free Member
 

Your daughters?

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


 
Posted : 06/09/2012 3:56 pm
Posts: 91097
Free Member
Topic starter
 

They are pretty naughty at times.


 
Posted : 06/09/2012 4:01 pm
Posts: 0
Free Member
 

They are pretty naughty at times.

you're doing yourself no favours...


 
Posted : 06/09/2012 4:03 pm
Posts: 0
Free Member
 

🙂


 
Posted : 06/09/2012 4:03 pm
 poly
Posts: 8748
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!
[code]
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)

[/code]

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


 
Posted : 06/09/2012 7:28 pm
Posts: 4954
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?


 
Posted : 06/09/2012 7:32 pm
Posts: 0
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.


 
Posted : 06/09/2012 10:42 pm
Posts: 77691
Free Member
 

Loving your alternative choice. Far more constructive.


 
Posted : 06/09/2012 10:50 pm