Set date from directory name

Started by RayArdia, December 21, 2011, 11:26:07 AM

Previous topic - Next topic

RayArdia

Hi Phil,
As I can't yet look at my "Exiftool for Dummies manual I'll have to ask!
I have groups of scanned and cropped images of some old family photos stored in folders by  approximate year taken. Shotwell is my photo manager and because it has NO manual at all I don't know what parameters it  uses to sort imported images.  Doubtless it requires at least some form of metadata because the imports end up in 'folders' marked by Year with sub-folders for Months.

Since my scanned images (Stored by year in folders in Desktop) have no metadata, how do I go about setting up a data file for each image showing at least Date Original YYYY,MM.
Can I set this up by batches  ie all images in the 1989 folder to have the same YYYY but perhaps split into 4 or so sub-batches where I can remember (or more likely guess) the month?

Sorry to be a PIA,
Ray

Phil Harvey

Hi Ray,

If you can set up the images in YYYY\MM folders, then you can do this to set the value of DateTimeOriginal from the directory names:

exiftool "-datetimeoriginal<${directory}:01 00:00:00" -r c:\images

Here I have assumed that the image directories are all inside the "c:\images" directory.  The command will work as long as this top-level directory name doesn't contain 4 digits (in which case, exiftool would take this as the year).

So with this command, the file "c:\images\2001\09\test.jpg" will have DateTimeOriginal set to "2001:09:01 00:00:00", etc.

After the command is run, all original images will be preserved with a "_original" added to the file name.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

RayArdia

Hi Phil,
Thank you.....but I'm still a bit puzzled.  The relevant structure is (I am using Ubuntu 11.10) /Ray/Desktop/1989/Images.jpg
Should I therfore put this at Command Line:-

exiftool "-datetimeoriginal<${Ray or Desktop or 1989}:1989:04:27" -r c:\images (for a date/time/Original 27th April 1989)
Ray


Phil Harvey

Hi Ray,

Ah.  With Ubuntu the quoting will be different.  In your example the images are not in subdirectories by month, so you would type this exactly (assuming the "Ray" directory is at the root level of your filesystem, which is a bit odd):

exiftool '-datetimeoriginal<${directory}:01:01 00:00:00' -r /Ray/Desktop

However, I suggest moving the year directories somewhere other than your desktop (and changing "/Ray/Desktop" in the above command accordingling), because this command will process images in all contained subdirectories.

- Phil

Edit: But I see that you want to use a date of April 27 in your example.  Are you going to do all image dates individually like this, or do you want to batch process the images and fill in the dates based only on the directory names?  The command to do it individually is:

exiftool '-datetimeoriginal=1989:04:27 00:00:00' /Ray/Desktop/1989/images.jpg
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

RayArdia

What I want to do is give each of the images contained folder 1989 a 'date timeoriginal' which will read 1989:04:00:00. BTW Ray is my home directory, not root.

Phil Harvey

Hi Ray,

To do images only a single directory, the command is simpler:

exiftool '-datetimeoriginal=1989:04:01 00:00:00' ~/Desktop/1989

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

RayArdia

Hi Phil,
SUCCESS! I now have all 50 images in their proper slot in Shotwell.
Will be in touch again soon.
Ray

RayArdia

Quote from: Phil Harvey on December 21, 2011, 03:45:33 PM
Hi Ray,

To do images only a single directory, the command is simpler:

exiftool '-datetimeoriginal=1989:04:01 00:00:00' ~/Desktop/1989

- Phil

Hi Phil,
Well...... all went fine the last time (in December2011) I used Exiftool to give a new DateTimeOriginal to assorted scanned images. BUT now I return to the task I keep getting it wrong - I just can't believe I can be this stupid!
The images are in folder 1994 in Desktop.
Here's the terminal sequence , what am I doing wrong please?

ray@ray-Aspire-5735:/$ ls
bin    etc             lib         opt   sbin     tmp      vmlinuz.old
boot   home            lost+found  proc  selinux  usr
cdrom  initrd.img      media       root  srv      var
dev    initrd.img.old  mnt         run   sys      vmlinuz
ray@ray-Aspire-5735:/$ exiftool '-datetimeoriginal=1994:04:01 00:00:00' ~/Desktop/1994
Error: File not found - /home/ray/Desktop/1994
    0 image files updated
    1 files weren't updated due to errors
ray@ray-Aspire-5735:/$ cd home
ray@ray-Aspire-5735:/home$ exiftool '-datetimeoriginal=1994:04:01 00:00:00' ~/Desktop/1994
Error: File not found - /home/ray/Desktop/1994
    0 image files updated
    1 files weren't updated due to errors
ray@ray-Aspire-5735:/home$ ls
ray
ray@ray-Aspire-5735:/home$ cd ray
ray@ray-Aspire-5735:~$ exiftool '-datetimeoriginal=1994:04:01 00:00:00' ~/Desktop/1994
Error: File not found - /home/ray/Desktop/1994
    0 image files updated
    1 files weren't updated due to errors
ray@ray-Aspire-5735:~$

Kindest regards, Ray


Phil Harvey

Hi Ray,

All of the commands look good, but they all are looking for a folder called "1994" on your desktop, which apparently doesn't exist.  Do this to see what is on your desktop:

ls ~/Desktop

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

RayArdia

ray@ray-Aspire-5735:~$ ls ~/Desktop
1949  1960   1994   1999   2010        land rover jan 2011 001.jpg
1950  1964  1996     2000  2012        land rover jan 2011 002.jpg
1952  1974  1997    2005   Dec28 1994  land rover jan 2011 004.jpg
1953  1984  1998    2008   Jan 1995    WS&S 7023.JPG
ray@ray-Aspire-5735:~$
Ray

Phil Harvey

Hi Ray,

There looks to be a space character before 1994 (and 2000).  Try renaming the folder to remove the space(s).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

RayArdia

Hi Phil,
Spot on! I don't know how you could tell, but that was the problem. As soon as I looked at the two folders 1994 and 2000 displayed on Desktop I noticed that they were shown out of numerical order even after a re-sort. Foolishly,  I had thought nothing of it at the time - I'll keep a sharper eye out in future!
Thank you very much for your help.
Kindest regards,
Ray

Phil Harvey

Hi Ray,

Great, I'm glad this fixed it.

I could tell because the columns didn't line up when you pasted the directory listing.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

RayArdia

Hi Phil, here I am again - sorry to be a pita!
I have been working through a mountain of old photos, using exiftool successfully. After an overnight pause in proceedings I went back to it today and encountered a snag.
I have 13 .jpg images in a folder '1993' but when I try the command 'exiftool '-datetimeoriginal=1993:09:10 00:00:00' ~/Desktop/1993' it doesn't work.
I suspected maybe an odd errant space, as before, so checked.-
ray@ray-Aspire-5735:~/Desktop$ ls
1949  1957  1961  1965  1976  1986  1990  1994  1998  2008  Dec28 1994
1950  1958  1962  1966  1983  1987  1991  1995  1999  2010
1952  1959  1963  1968  1984  1988  1992  1996  2000  2011
1953  1960  1964  1974  1985  1989  1993  1997  2005  2012
ray@ray-Aspire-5735:~/Desktop$ cd ~
ray@ray-Aspire-5735:~$ exiftool '-datetimeoriginal=1993:09:10 00:00:00' ~/Desktop/1993
    1 directories scanned
    0 image files read
A further 'ls' shows:-
ray@ray-Aspire-5735:~/Desktop/1993$ ls
1993-0  1993-10  1993-12  1993-3  1993-5  1993-7  1993-9
1993-1  1993-11  1993-2   1993-4  1993-6  1993-8
ray@ray-Aspire-5735:~/Desktop/1993$
I've looked at the Properties of all the images and everything seems OK. Any ideas?
Ray



Phil Harvey

Hi Ray,

The images are in sub-directories of ~/Desktop/1993, so you must add the -r option to your command to recurse into sub-directories.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).