Setting FILE-WRITE-DATE 
Author Message
 Setting FILE-WRITE-DATE

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



Tue, 16 Apr 2002 03:00:00 GMT  
 Setting FILE-WRITE-DATE

| 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



Tue, 16 Apr 2002 03:00:00 GMT  
 Setting FILE-WRITE-DATE


Quote:

> | 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.

Quote:
>   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;

Quote:
}

******************** 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



Tue, 16 Apr 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Set File last written date

2. - Setting the creation/modification date for files - HOW ?

3. Set file date and time with API call

4. How Set (not Get) file time and date....?

5. Setting the date of a file in Xbase++

6. Touching a file (set to current time and date)

7. How to set file date and time in OS/2

8. how to set file date and times in rexx on os/2

9. Setting file creation date

10. Setting file creation date

11. Writing the date/time to output files.

12. Correct behavior for file-write-date?

 

 
Powered by phpBB® Forum Software