EXIF Rename..

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
aimy
Posts: 181
Joined: 26 Feb 2007 15:44

EXIF Rename..

Post 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.

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: EXIF Rename..

Post 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  
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

aimy
Posts: 181
Joined: 26 Feb 2007 15:44

Re: EXIF Rename..

Post 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:

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: EXIF Rename..

Post 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply