newLISP Fan Club

Forum => newLISP and the O.S. => Topic started by: aron on August 26, 2008, 01:15:05 AM

Title: Write to file without changin Date modified
Post by: aron on August 26, 2008, 01:15:05 AM
Hi i use:



http://www.newlisp.org/downloads/newlisp_manual.html#write-file



To uppdate textfiles, but i don't want the "Date modified" uppdated.



Can I do that in some way?
Title:
Post by: Jeff on August 26, 2008, 05:04:56 AM
Yes, by writing your own filesystem :)
Title:
Post by: hsmyers on August 26, 2008, 10:14:59 AM
I've no clue of how to do it in newLisp, but since the 'touch' utility does it all of the time, I don't think you would have to 'rewrite' the OS...



--hsm
Title:
Post by: cormullion on August 26, 2008, 10:33:34 AM
I would try something like:



(set 'mod-date (date (file-info item 6) 0 "%Y%m%d%H%M.%S"))

; modify item

(exec (string "touch -t " mod-date " " item))



or something. Presumably there's a 'touch' command on Windows...
Title:
Post by: DrDave on August 26, 2008, 11:25:25 AM
Quote from: "cormullion" Presumably there's a 'touch' command on Windows...

No, there isn't.  However Lutz' coding of  file-info for retrieving the data might show the way to set the data.
Title:
Post by: hsmyers on August 26, 2008, 12:54:10 PM
Windows doesn't come with 'touch'--- but it is widely available on the net. I've never thought about it since I've always had it in my toolkit as a developer. It is trivial to write. Seems to me that in the long ago days one came with the Borland dev kits. Not having it is sort of like not having grep ;)



--hsm
Title:
Post by: aron on August 27, 2008, 03:23:53 AM
Hi and thanx for you replys.



So what you say is that one solution is to, get a touch for Windows and then read the "Date modified" value, uppdate the file and then set back the value afterwards.



Will maybe try fixing that.



edit: Maybe I can use the version of touch from: http://gnuwin32.sourceforge.net/packages/coreutils.htm
Title:
Post by: hsmyers on August 28, 2008, 09:20:25 AM
aron,



Actually I'd do both--- first acquire a working 'touch'. The one you point to is a good one, as are the rest of their Unix tools; get them all, you will need them sooner or later. Second, see if newLISP can solve your problem by trying the other suggestions made here. It will teach you more about both newLISP and the file system. Both worth knowing.





--hsm
Title:
Post by: m35 on August 28, 2008, 06:41:35 PM
If your target is Windows, you could also wield the win32api directly through (import) (//http).



Here is a page showing what win32api functions do what (written in Visual Basic).



http://vbnet.mvps.org/code/fileapi/filedatetime.htm
Title:
Post by: hsmyers on August 28, 2008, 08:39:11 PM
While I suppose you could go through the Win32 API, here is all you really need:



INT 21 Function 5701h:SET FILE'S LAST-WRITTEN DATE AND TIME



AX = 5701h

BX = file handle

CX = new time

DX = new date



Return:

CF clear if successful CF set on error AX = error code (01h,06h)



Bitfields for file time:

Bit(s) Description

15-11 hours (0-23)

10-5 minutes

4-0 seconds/2



Bitfields for file date:

Bit(s) Description

15-9 year - 1980

8-5 month

4-0 day



1. write dll in assembler

2. write glue in newLISP

3. use



--hsm

p.s. note that this function is handle based, so you will have to open the file you want to touch. Probably could get away without closing, but to be safe, call the close function as well.
Title:
Post by: m35 on August 28, 2008, 08:57:55 PM
Quote from: "hsmyers"INT 21 Function


You can still do that? O_O



Wow...



But shouldn't there be POSIX functions that can modify a file's Last Modified date? I suppose that would be the most cross-platform approach.
Title:
Post by: DrDave on August 28, 2008, 10:14:59 PM
Quote from: "m35"
Quote from: "hsmyers"INT 21 Function


You can still do that? O_O



Yes, the interrupts still work, but it is frowned upon to use them. MS claims they may not be reliable anymore.