Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting FILE-WRITE-DATE

11 views
Skip to first unread message

Marc Battyani

unread,
Oct 29, 1999, 3:00:00 AM10/29/99
to
Is there a way to set the FILE-WRITE-DATE of a file.
I can call a C funcfion but I would prefer to avoid this.

Marc Battyani

Erik Naggum

unread,
Oct 29, 1999, 3:00:00 AM10/29/99
to
* "Marc Battyani" <Marc_B...@csi.com>

| Is there a way to set the FILE-WRITE-DATE of a file.
| I can call a C funcfion but I would prefer to avoid this.

so you would prefer that somebody else did the dirty work, instead? :)

if you want a SETF method on FILE-WRITE-DATE, you can write your own, but
you can't also claim to have strictly conforming and portable code. this
may not be such a terrible loss, compared to a SET-FILE-WRITE-DATE or a
function that takes gratuitously different arguments.

#:Erik

Marc Battyani

unread,
Oct 29, 1999, 3:00:00 AM10/29/99
to

Erik Naggum <er...@naggum.no> wrote in message
news:31501722...@naggum.no...

> * "Marc Battyani" <Marc_B...@csi.com>
> | Is there a way to set the FILE-WRITE-DATE of a file.
> | I can call a C funcfion but I would prefer to avoid this.
>
> so you would prefer that somebody else did the dirty work, instead? :)
Yes, if it's well done...
Avoiding to dig into the NT SDK is always welcome.

> if you want a SETF method on FILE-WRITE-DATE, you can write your own,
but
> you can't also claim to have strictly conforming and portable code.
this
> may not be such a terrible loss, compared to a SET-FILE-WRITE-DATE or a
> function that takes gratuitously different arguments.

OK, here it is
It work almost... see example at the end.

;; (setf file-write-date) function for Harlequin LispWorks under NT
;; Copyright (C) Marc Battyani 1999
;; Everybody can do whatever they want with this except preventing me to use
it.
;; As usual I decline all responsibilities : Use it at your own risk.
;; If anybody has a well thought legal license in this spirit please send it
to me.
;; If you add ameliorations and/or portage to other platforms please send
them to me

(fli:define-foreign-function (%nt-set-file-time "NTSetFileTime")
((key-path :pchar)(Year :short)(Month :short)(Day :short)(Hour
:short)(Minute :short)(Second :short)(Milliseconds :short))
:language :ansi-c
:calling-convention :cdecl
:result-type (:boolean :long)
:module "LispUtilities.dll")

(export '(setf file-write-date))
(defun (setf file-write-date)(new-time path-des)
(multiple-value-bind (second minute hour date month
year)(decode-universal-time new-time)
(let ((file-name (namestring (truename path-des))))
(check-type file-name string)
(fli:with-foreign-string (nt-file-name element-count byte-count
:external-format win32:*multibyte-code-page-ef*) (namestring (truename
path-des))
(declare (ignore byte-count element-count))
(%nt-set-file-time nt-file-name year month date hour minute second
0)))))

******************* the C stuff to put in a DLL*****************
DLLExport BOOL NTSetFileTime(char *FileName, short wYear, short wMonth,
short wDay, short wHour, short wMinute, short wSecond, short wMilliseconds)
{
SYSTEMTIME STime;
FILETIME FTime;
HANDLE FileHandle;
BOOL OK;

STime.wYear = wYear;
STime.wMonth = wMonth;
STime.wDayOfWeek = 0; //ignored
STime.wDay = wDay;
STime.wHour = wHour;
STime.wMinute = wMinute;
STime.wSecond = wSecond;
STime.wMilliseconds = wMilliseconds;

if (!SystemTimeToFileTime(&STime, &FTime))
return FALSE;

FileHandle = CreateFile(FileName, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
if (FileHandle == INVALID_HANDLE_VALUE)
return FALSE;

OK = SetFileTime(FileHandle, NULL, NULL, &FTime);

CloseHandle(FileHandle);

return OK;
}

******************** end of C stuff *******************

some tests now:

UTILITY 4 > (file-write-date #P"d:/temp/ap.java")
3149868889

UTILITY 5 > (get-universal-time)
3150196853

UTILITY 6 > (setf (file-write-date #P"d:/temp/ap.java") *)
t

UTILITY 7 > (file-write-date #P"d:/temp/ap.java")
3150200453

UTILITY 8 > (- * ***)
3600

OK it's the time zone. Now if I look at the file on the disk the time given
has a 2 hours difference!
Any help will this timezone mismatch will be welcome.

Cheers,

Marc Battyani


0 new messages