[Tugindia] Date of file

CV Radhakrishnan cvr at river-valley.com
Sat Nov 19 06:58:17 CET 2005

On Fri, November 18, 2005 10:36 am, Kapil Hari Paranjape said:
> Hello,
> I'm creating some print-outs of some old TeX files.
> Is there some way (short of editing the files) to
> get TeX to set the "date" header in the output to
> the date of last modification of the file?

Here is one way to do the job (assuming that you use GNU/Linux or some
Unix and the TeX installation is web2c ie., teTeX or TeXLive):

Few macros to capture the last modified date from the ls -l command of Linux.

==================== start of the macros ========================
\def\mydate #1-- #2 #3 #4 #5 #6\endmydate{\findFileDate#6\@nil}
\def\findFileDate#1 #2 #3 #4\@nil{%

    \immediate\write18{echo "\string\mydate" > date.tex}%
    \immediate\write18{ls -l \jobname.tex >> date.tex}%
    \immediate\write18{echo "\string\endmydate" >> date.tex}%
    \input date.tex%
    File name: \fileName\par
    Last Modified: \dateLastModified}


=================== end of macros ======================

Save the above macros in a file, say printdate.tex.

Now issue the command to compile your document in the following fashion:

  [pdf]latex -shell-escape '\AtBeginDocument{\input printdate} \input

(assuming your document's file name is test.tex).  I have tested this in
my system and works fine as expected.  The filename and file modification
dates are printed at the end of the document.

You might take note that your are invoking shell-escape function of TeX,
meaning TeX escapes from the compilation process and gets a shell to
execute certain functions (here it is ls -l).  After that, it continues
the compilation and finishes as usual.  Be warned that you can do harm to
your system if you dont know what you're doing.

You can modify your class file to include the file modification date as a
footer or whatever, because once \printDate function is executed, you have
two macros defined

 1) \fileName   (name of your file which is otherwise available as \jobname)
 2) \dateLastModified (file modification date)

You can make use of these macros.  \let\today\dateLastModified will change
the behaviour of the \today macros to the file modification date.



More information about the tugindia mailing list