Page 1 of 1

Copying only JPG files

PostPosted: Tue Apr 02, 2013 11:19 pm
by gsomby
I shoot RAW+JPG and copy the files to a \YYYY\MM\DD folder structure using a batch macro.
I want to create a new macro that moves the JPGs to a sub-folder, but I only want to move the JPGs it has a matching RAW-file. The reason is that I also copy photos shot with my mobile (which only creates JPGs) into my main folder structure.

Is there any way to achieve what I want?

/Gunnar

Re: Copying only JPG files

PostPosted: Wed Apr 03, 2013 12:06 am
by Axel
Yes, but this would involve a custom condition (as there is a decision to make at run time, i.e. check for the presence of a matching raw, and only move the file if this is the case).

You could create a rule that moves only JPEGs to a subfolder of your choice using a "file type" condition set to JPEG, and a move action. This will move all JPEG files indiscriminately.

Next, add a second condition, namely a Custom Condition and test the "File.Extensions" variable, to see if, say, a CR2 is associated with the JPEG at hand.

The move action will only execute if both conditions are met, achieving what you want.

The Custom condition will basically consist in a 1-line JavaScript function, that will test the "File.Extensions" variable and return a Boolean True or False depending on what is found in it. The function gives its thumbs up by returning True.

The following is just from the top of my head and was NOT tested, but it should be enough to get you started.

Code: Select all
// Returns true if there is a Canon CR2 raw file in the current image stack.

function Evaluate(context)
{
    return context("File.Extensions").indexOf("cr2") >= 0 ? 1 : 0;
}

Save the above code to a file, say "HasCR2.js" and use it as your custom condition. The above function may require some minor tweaks but the idea is there.

There is a couple of sample custom condition written in JavaScript that you will find here on Windows 7 or 8: C:\ProgramData\FastPictureViewer\Scripts\Samples\Condition Scripts, you may want to read those files, in particular the comments in them, this may help you get a feel of what's possible.

Let me (and the rest of us) know how you eventually achieved the result you want, or if you need more assistance with custom conditions!

In a nutshell: if you need a selection criteria that is not available among the 25 existing ones, write your own! 8-)

Tip: you could also write a custom action if desired (but in your case, moving to a subfolder, absolute or relative, is pretty well covered by the built-in Move action already).

OK, that's one way, that will work in general. If you know some specifics about the file names, for example that all JPEG+RAW pairs are always named DSC_XXXX.jpg and DSC_XXXX.cr2, and you other JPEGs follows a distinct naming convention, you can simply use a pattern-matching expression on the file name to pick only the JPEGs you want (or reject the ones you don't want).

This can be done with the build-in Filename Condition (or Exception), very selectively if needed using regular expressions, and is perhaps simpler as you directly exploit knowledge about the file name formats.

Re: Copying only JPG files

PostPosted: Tue Apr 09, 2013 1:54 am
by gsomby
Axel wrote:The following is just from the top of my head and was NOT tested, but it should be enough to get you started.

Code: Select all
// Returns true if there is a Canon CR2 raw file in the current image stack.

function Evaluate(context)
{
    return context("File.Extensions").indexOf("cr2") >= 0 ? 1 : 0;
}
...

C:\ProgramData\FastPictureViewer\Scripts\Samples\Condition Scripts, you may want to read those files, in particular the comments in them, this may help you get a feel of what's possible.


The above code did not work [edit: was corrected since!], but I looked at your sample scripts and modified the code like this:
Code: Select all
// Returns true if there is a DNG raw file in the current image stack.

function Evaluate(context)
{
    return context("File.Extensions").indexOf("DNG") >= 0 ? 1 : 0;
}

And this works well.
Thanks a lot for the help

Re: Copying only JPG files

PostPosted: Thu Apr 11, 2013 5:49 pm
by Axel
Yeah, that's the spirit! :D Glad to know you got the result you were after, congratulations!

Scripted conditions (and actions) open the door to almost every imaginable combinations of selection criteria and operations, for example you could use exiftool, curl, the Scripting.FileSystemObject or ImageMagick in a scripted custom action to perform metadata edits, file transfers or manipulations, or even image processing. Any scriptable ActiveX object can be instantiated and used directly from the scripts and the WScript.Shell object can be used to run external programs.

Similarly, a custom scripted conditions can use data from more than a hundred pre-defined variables and perform complex logic to decide if a file must be processed or not.

The scripts execute in a full-fledged JavaScript / VBScript environment with dozens of built-in functions so you could write quite sophisticated code in there, and FastPictureViewer's File Utilities plug-in will take care of executing your rules with custom conditions and actions in parallel on multiple files at once, to leverage the power of all processors in your computer.

Re: Copying only JPG files

PostPosted: Mon Sep 16, 2013 12:07 am
by Axel
Starting from FPV Pro 1.9.0.318 there is a new native condition in the File Utilities plug-in, named "Siblings", which allows for selecting (or not selecting) files which have (or do not have) a given sibling. This does what is desctibed in this discussion without the need for a custom script, for example to select files if and only if a DNG exists in the stack (as in the example above) the new condition would read

Code: Select all
Where the image has a DNG sibling then ...

There are provisions for negation ("does not have") as well as for looking for multiple extensions, with wildcard support. Nothing that could not be done in a script, but for most users point-and-click is much easier 8-)