Wednesday, July 4, 2007

Get Creation Or Modification Date Of A File

After quite a long search, I finally found some standard Rexx functionality I've been looking for.

Cosmogrammaticus mentioned before the lack of marketing for Rexx, and I've been thinking that it really shows in the lack of documentation and tutorials that are out there in easily-found places.

Anyway, in my main and alternate workplaces, there has been a continuing cry for a quick tool to sort JPEGs by date.  In both places, there are photos uploaded from HP cameras that need to be easily found by the date they were taken.  In some cases, a selection of these photos is inserted into a word processor or spreadsheet file (Word, Excel, OpenOffice Writer, OpenOffice Calc).  In other cases, a selection of these photos is sent alongside the word processor or spreadsheet file as e-mail attachments.  The common case is that there are a fairly large number of photos (but only a subset is actually used) with specific dates being tied to specific events or locations that are the subject of the accompanying documents.

In an all-Windows environment, I finally implemented a KiXtart version of this functionality.  This article is the basis for doing something similar with Rexx.


#!/usr/bin/env rexx
/* If not using Linux or Unix, delete these first two lines. */
/* filedate.rex: displays the file creation or modification date */

parse arg targetfile
if targetfile = "" then do
call usage
end
else do
filedate = stream(targetfile, 'c', 'QUERY TIMESTAMP')
say "The file" targetfile " was last modified " filedate
/* See http://www.rexxla.org/About_Rexx/mfc/datec.html */
end

/* trap execution so error message does not show */
exit

usage:
say "Usage: rexx filedate.rex filename"
return


I was quite surprised to find this, because I've searched through my books and searched online tutorials for a few months looking for this. Then, suddenly, here it is right in front of my eyes.  To use this, open a terminal and type rexx filedate.rex <filename> and it will display the date for that file. Replace the filename in angle brackets with the file you are interested in (skip the angle brackets, too).

This is the kind of thing that we want to be able to whip up fairly quickly in response to the needs of our users.

Depending on the schedule and events, I should get a usable version of the sort-JPEGs-by-date script up shortly.

Blogged with Flock

1 comments:

All comments are moderated. Your comment will show up after approval.