I was given several dozen digital photos that I wanted to add to my collection. However, the camera used did not have the date/time set. Worst still, each time the camera was turned on, the camera clock started ticking from the same time (1/1/2004 midnight).

 

With certain display modes of my picture display program and screen saver, the pictures are sorted by date/time stamp order. However, because these pictures were from several events, the pictures appeared to be in a random order. In fact, they were in date/time order, so the first picture displayed was the one closest to the time of the camera power on, and the last was the one with the camera on the longest.

 

I wrote a simple program to adjust the file timestamps to be at least in chronological order based on the picture sequence number, which was chronological. Of course, this did not change the Exif JPG picture properties directly stored inside the JPG file.

 

See also:

Draw text or graphics directly onto a JPG file

Sharing Digital Pictures of your friend's

Make an interactive screen saver

 

 

 

n=ADIR(aa,cPath+"*.*")

ASORT(aa,1,n)

FOR i = 1 TO n

          retimestamp(cPath+aa[i,1],CTOT("11/27/06")+i*3600)

          ?aa[i,1],aa[i,3],aa[i,4]

ENDFOR

RETURN

 

 

 

*From WINNT.H:

#define FILE_SHARE_READ                 0x00000001 

#define FILE_SHARE_WRITE                0x00000002 

#define FILE_SHARE_DELETE               0x00000004 

#define FILE_ATTRIBUTE_READONLY             0x00000001 

#define FILE_ATTRIBUTE_HIDDEN               0x00000002 

#define FILE_ATTRIBUTE_SYSTEM               0x00000004 

#define FILE_ATTRIBUTE_DIRECTORY            0x00000010 

#define FILE_ATTRIBUTE_ARCHIVE              0x00000020 

#define FILE_ATTRIBUTE_DEVICE               0x00000040 

#define FILE_ATTRIBUTE_NORMAL               0x00000080 

#define FILE_ATTRIBUTE_TEMPORARY            0x00000100 

#define FILE_ATTRIBUTE_SPARSE_FILE          0x00000200 

#define FILE_ATTRIBUTE_REPARSE_POINT        0x00000400 

#define FILE_ATTRIBUTE_COMPRESSED           0x00000800 

#define FILE_ATTRIBUTE_OFFLINE              0x00001000 

#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000 

#define FILE_ATTRIBUTE_ENCRYPTED            0x00004000 

#define FILE_WRITE_ATTRIBUTES                                0x100

#define GENERIC_WRITE     (0x40000000)

#define GENERIC_READ      (0x80000000)

 

 

*From winbase.h:

#define CREATE_NEW          1

#define CREATE_ALWAYS       2

#define OPEN_EXISTING       3

#define OPEN_ALWAYS         4

#define TRUNCATE_EXISTING   5

 

PROCEDURE ReTimeStamp(cFilename as string, dt as Datetime)

                   DECLARE integer CreateFile in win32api string, integer dwDesiredAccess, integer dwShareMode, integer security, ;

                             integer dwCreationDisposition, integer FlagsAttrs, integer hTemplate

                   DECLARE INTEGER CloseHandle in win32api integer hFile

                   DECLARE integer SystemTimeToFileTime IN WIN32API string , string @

                   DECLARE INTEGER SetFileTime IN kernel32;

                             INTEGER hFile, STRING lpCreationTime,;

                             STRING lpLastAccessTime, STRING lpLastWriteTime

                   DECLARE INTEGER SystemTimeToFileTime IN kernel32;

                             STRING lpSystemTime, STRING @lpFileTime

                   DECLARE INTEGER LocalFileTimeToFileTime IN kernel32;

                             STRING lpLocalFileTime, STRING @lpFileTime

                   DECLARE integer GetLastError in win32api

 

                   cFileTime = SPACE(8)

                   cSysTime=BINTOC(YEAR(dt),"2rs") + ;

                                      BINTOC(MONTH(dt),"2rs") + ;

                                      BINTOC(DOW(dt,0),"2rs") + ;

                                      BINTOC(DAY(dt),"2rs") + ;

                                      BINTOC(HOUR(dt),"2rs") + ;

                                      BINTOC(MINUTE(dt),"2rs") + ;

                                      REPLICATE(CHR(0),4)

                   SystemTimeToFileTime(cSysTime, @cFileTime)

 

                   LocalFileTimeToFileTime(cFileTime, @cFileTime)

 

                   hFile = CreateFile(cFilename, GENERIC_WRITE+GENERIC_READ,FILE_SHARE_READ, 0, OPEN_EXISTING, 0,0)

                   SetFileTime(hFile , cFileTime, cFileTime,cFileTime)

                   CloseHandle(hFile)

 

RETURN