Page 1 of 1

EXIF Rename..

Posted: 27 May 2015 06:02
by aimy
Hi all.

I have this script with the help some of you here

Code: Select all

$shift = 8; // Time (in hours to shift the time)
    $previewNames = "";
    $ahkHelper = "D:\SugarSync\Programs\Settings\xyEditItemNamesWindow_Helper.exe";

    $clip = "<clipboard>"; // Store current clipboard data

    foreach($item, <get SelectedItemsPathNames |>, "|") {
        $device = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        $extension = getpathcomponent($item, "ext");
        $date = formatdate(property("WhenTaken", $item), "yyyymmdd.hhnnss", "h", $shift);
        if ($device == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            $pattern = "$date-$baseName¬SAMSUNG PL151.$extension";
        } elseif ($device == "SM-N9005") {
            $pattern = "$date¬SM-N9005.$extension";
        } elseif ($device == "808 PureView") {
            $fileName = RegExReplace($baseName, "(\S{10})[-](.+)", "$2");
            $pattern = "$date-$fileName¬$device.$extension";               
        } else {
            $pattern = "$date-$baseName¬$device.$extension";
        }
        $previewNames = $previewNames . $pattern . "<crlf>";
    }
    $previewNames = formatlist($previewNames, "e", "<crlf>");
    copytext "$previewNames";
    run """$ahkHelper""";
    #147;
    copytext $clip; // Restore clipboard data  
The script works fine except for that it will return error if the selected file does not contain the Time Taken (EXIF info). If this happen, I want the script to retain the filename without doing anything.

So, can someone here please help me on how do I prevent such error from occur?

Thank you.

Re: EXIF Rename..

Posted: 27 May 2015 08:37
by SammaySarkar
this might help

Code: Select all

$shift = 8; // Time (in hours to shift the time)
    $previewNames = "";
    $ahkHelper = "D:\SugarSync\Programs\Settings\xyEditItemNamesWindow_Helper.exe";

    $clip = "<clipboard>"; // Store current clipboard data

    foreach($item, <get SelectedItemsPathNames |>, "|") {
        $device = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        $extension = getpathcomponent($item, "ext");
        $whenTaken = property("WhenTaken", $item);
        if ($whenTaken == '') { continue; }
        $date = formatdate($whenTaken, "yyyymmdd.hhnnss", "h", $shift);
        if ($device == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            $pattern = "$date-$baseName¬SAMSUNG PL151.$extension";
        } elseif ($device == "SM-N9005") {
            $pattern = "$date¬SM-N9005.$extension";
        } elseif ($device == "808 PureView") {
            $fileName = RegExReplace($baseName, "(\S{10})[-](.+)", "$2");
            $pattern = "$date-$fileName¬$device.$extension";               
        } else {
            $pattern = "$date-$baseName¬$device.$extension";
        }
        $previewNames = $previewNames . $pattern . "<crlf>";
    }
    $previewNames = formatlist($previewNames, "e", "<crlf>");
    copytext "$previewNames";
    run """$ahkHelper""";
    #147;
    copytext $clip; // Restore clipboard data  

Re: EXIF Rename..

Posted: 27 May 2015 09:03
by aimy
SammaySarkar wrote:this might help

Code: Select all

$shift = 8; // Time (in hours to shift the time)
    $previewNames = "";
    $ahkHelper = "D:\SugarSync\Programs\Settings\xyEditItemNamesWindow_Helper.exe";

    $clip = "<clipboard>"; // Store current clipboard data

    foreach($item, <get SelectedItemsPathNames |>, "|") {
        $device = property("CameraModel", $item);
        $baseName = getpathcomponent($item, "base");
        $extension = getpathcomponent($item, "ext");
        $whenTaken = property("WhenTaken", $item);
        if ($whenTaken == '') { continue; }
        $date = formatdate($whenTaken, "yyyymmdd.hhnnss", "h", $shift);
        if ($device == "SAMSUNG PL150 / VLUU PL150 / SAMSUNG TL210 / SAMSUNG PL151") {
            $pattern = "$date-$baseName¬SAMSUNG PL151.$extension";
        } elseif ($device == "SM-N9005") {
            $pattern = "$date¬SM-N9005.$extension";
        } elseif ($device == "808 PureView") {
            $fileName = RegExReplace($baseName, "(\S{10})[-](.+)", "$2");
            $pattern = "$date-$fileName¬$device.$extension";               
        } else {
            $pattern = "$date-$baseName¬$device.$extension";
        }
        $previewNames = $previewNames . $pattern . "<crlf>";
    }
    $previewNames = formatlist($previewNames, "e", "<crlf>");
    copytext "$previewNames";
    run """$ahkHelper""";
    #147;
    copytext $clip; // Restore clipboard data  
So far it works as expected.. :tup:

Thank you so much Sir.. :beer:

Re: EXIF Rename..

Posted: 27 May 2015 14:08
by SammaySarkar
Great! :beer:

My changed bits just confirm that the "when taken" property actually has a value before calling formatdate(). formatdate() cannot accept strings that are not dates, and throws an error.