5000 iPhone images: how to handle them?

Dear VisualNeo Win user,

Someone asked me last week:

Reinier, I’ve 5000 iPhone photos. Can you organize them for me, putting them in separate folders?
The name of the folder can be equal to the year the images were recorded. Could the creation date be used in the filename of the image? Thank you!

I was successful in finding a solution with VisualNeo Win and newLISP. As a follow up of my tutorials on newLISP, I present you the annotated code below. A complete functional sample PUB, an image folder and the necessary newlisp.dll can be downloaded here: https://visualneo.com/downloads/phototool.zip

Unzip it and avoid pathnames with spaces!

Notice that you have to install Hans-Peter Wickern’s newLISP plugin from: https://visualneo.com/product/hpwnewlisp.

Remark: unfortunately, EXIF tools are not always useful. Sometimes an image does not contain EXIF data (see sample image folder IMG_4.jpg), but has always the file property of the modification time (equal to the original file creation date if the photos were not manipulated) … at least this seems to be true for the 5000 iPhone photos, I had to process. So I used the modification date for making foldernames and modified filenames.

The sample program determines the modification date of file IMG_3.JPG, rename this file to 2014-08-28_IMG_3.JPG and put it into the newly created folder 2014. Another example: the sample file IMG_2.JPG will be -according to its modification date- renamed to 2015-06-13_IMG_2.JPG and put into folder 2015.

I hope it is helpful. Thank you for reading!

Best regards,
Reinier Maliepaard

Code

. Assign the variable [img-folder] a value (without [PubDir])

SetVar “[img-folder]” “img-sample-folder”

.The sample folder has three JPG files: IMG_1.JPG, IMG_2.JPG, IMG_3.JPG and IMG_4.JPG

…………………………………………………………………………………………………………..
. Step 1: give a list of all image files in the folder [img-folder]
. in the sample case all image files had the extension .JPG
…………………………………………………………………………………………………………..

. You could use:
. FileList “[PubDir][img-folder]\*.jpg” “Files” “[img-list]”
. However, FileList is very slow.
. The fast newLISP alternative is:

hpwNewLispCall “(map sym (directory {[nlPubDir][img-folder]} {.+\.jpg|.+\.JPG}))” “[img-list]”

. Some explanations:
. [nlPubDir] is used in newLISP commands and is defined in the sample PUB in Book Properties > Actions > Startup.
. (directory {[nlPubDir][img-folder]} {.+\.jpg|.+\.JPG})) returns a list of all files with extension .jpg or .JPG.
. The result, a newLISP list of strings, i.e. (“IMG_1.JPG” “IMG_2.JPG” “IMG_3.JPG” “IMG_4.JPG”) is assigned to [img-list].
. This output is not appropriate for VisualNeo, so you’ve to remove the double apostrophes.
. ‘map sym’ makes of all strings so called symbols: (IMG_1.JPG IMG_2.JPG IMG_3.JPG IMG_4.JPG).

. In addition you’ve to remove the parentheses. You can do that easily with StrDel and Strlen
. StrDel “[img-list]” “1” “1” “[img-list]”
. StrLen “[img-list]” “[img-len]”
. StrDel “[img-list]” “[img-len]” “1” “[img-list]”

.But newLISP has a concise alternative

hpwNewLispCall “(slice (string ‘[img-list]) 1 -1)” “[img-list]”

. Notice that [img-list] has to be quoted in order to cast the list into a string
. to which the function ‘slice’ can be applied.

……………………………………………………………………………………………………….
. Step 2: parse the [img-list] in order to scan all image files.
……………………………………………………………………………………………………….
. In case of FileList, split [img-list] by delimiter [#13]
. StrParse “[img-list]” “[#13]” “[img]” “[number-of-img]”

. In case of the newLISP solution split [img-list] by delimiter ‘space’.

StrParse “[img-list]” ” ” “[img]” “[number-of-img]”

……………………………………………………………………………………………………………………………………………..
. Step 3: process each image file
. a. Put the modification date of each image file into the variable: [yyyy-mm-dd]
. b. Derive the year from the modification date and put it into [target-folder]
. c. Create the [target-folder] if it does not exist.
. d. Add the modification date as a prefix to the image filename.
. e. Copy the imagefile to the correct target folder.
……………………………………………………………………………………………………………………………………………..

Loop “1” “[number-of-img]” “[x]”

. Find the modification date and put its value into [yyyy-mm-dd]

hpwNewLispCall “(date (file-info {[nlPubDir][img-folder]/[img[x]]} 6) 0 {%Y-%m-%d})” “[yyyy-mm-dd]”

. Find the year of the modification date and assign its value to [target-folder].

hpwNewLispCall “(first (parse {[yyyy-mm-dd]} {-}))” “[target-folder]”

. Create [target-folder] if it does not exist.

FolderExists “[PubDir][target-folder]” “[folder-exists]”
If “[folder-exists]” “=” “false”
CreateFolder “[PubDir][target-folder]”
EndIf

. Add the modifcation date as a prefix to the image file name.
. Copy the image file to the right [target-folder]

FileCopy “[Pubdir][img-folder]\[img[x]]” “[Pubdir][target-folder]\[yyyy-mm-dd]_[img[x]]”

EndLoop

AlertBox “” “Done!”