ExifTool Forum

ExifTool => Newbies => Topic started by: RayArdia on December 21, 2011, 11:26:07 AM

Title: Set date from directory name
Post by: RayArdia on December 21, 2011, 11:26:07 AM
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
Title: Re: Set date from directory name
Post by: Phil Harvey on December 21, 2011, 11:48:47 AM
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
Title: Re: Set date from directory name
Post by: RayArdia on December 21, 2011, 02:27:07 PM
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

Title: Re: Set date from directory name
Post by: Phil Harvey on December 21, 2011, 02:45:45 PM
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
Title: Re: Set date from directory name
Post by: RayArdia on December 21, 2011, 03:20:50 PM
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.
Title: Re: Set date from directory name
Post by: 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
Title: Re: Set date from directory name
Post by: RayArdia on December 21, 2011, 04:15:23 PM
Hi Phil,
SUCCESS! I now have all 50 images in their proper slot in Shotwell.
Will be in touch again soon.
Ray
Title: Re: Set date from directory name
Post by: RayArdia on January 13, 2012, 02:32:07 PM
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

Title: Re: Set date from directory name
Post by: Phil Harvey on January 13, 2012, 03:24:34 PM
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
Title: Re: Set date from directory name
Post by: RayArdia on January 13, 2012, 04:19:24 PM
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
Title: Re: Set date from directory name
Post by: Phil Harvey on January 13, 2012, 08:08:02 PM
Hi Ray,

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

- Phil
Title: Re: Set date from directory name
Post by: RayArdia on January 14, 2012, 05:03:07 AM
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
Title: Re: Set date from directory name
Post by: Phil Harvey on January 14, 2012, 07:16:16 AM
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
Title: Re: Set date from directory name
Post by: RayArdia on January 30, 2012, 02:08:57 PM
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


Title: Re: Set date from directory name
Post by: Phil Harvey on January 30, 2012, 02:40:59 PM
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
Title: Re: Set date from directory name
Post by: RayArdia on January 30, 2012, 03:16:29 PM
Hi Phil,
There aren't any sub-directories to '1993', just 13 files within the dir 1993.
I thought I'd get on with some other photos so scanned some 1992 ones into ~/Desktop/1992.
Then:-
ray@ray-Aspire-5735:~$ exiftool '-datetimeoriginal=1992:09:10 00:00:00' ~/Desktop/1992
    1 directories scanned
   12 image files updated
So everything was normal as previously - so the tried:-
ray@ray-Aspire-5735:~$ exiftool '-datetimeoriginal=19932:09:10 00:00:00' ~/Desktop/1993
    1 directories scanned
   13 image files updated
ray@ray-Aspire-5735:~$    and the thirteen files I was having problems with are now "tooled-up" with the required metadata. I have no idea what happened but it seems to have sorted itself out.

So sorry to have bothered you, and thanks again for trying to put me straight.
Ray
Title: Re: Set date from directory name
Post by: Phil Harvey on January 30, 2012, 04:18:57 PM
Hi Ray,

In your directory listing, none of the files had ".jpg" extensions.  In fact, they didn't have extensions at all (they had names like "1993-0"), so I had assumed they were sub-directories.

ExifTool only processes files with recognized extension when processing a directory.  So for this to work, either the file names must have changed to include the extensions, or you changed your command to specify the files explicitly instead of the directory (ie. "~/Desktop/1993/*" instead of "~/Desktop/1993").

- Phil