Write to file without changin Date modified

Started by aron, August 26, 2008, 01:15:05 AM

Previous topic - Next topic

aron

Hi i use:



http://www.newlisp.org/downloads/newlisp_manual.html#write-file">http://www.newlisp.org/downloads/newlis ... write-file">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?
newLISP browser: (print (replace \"<[^>]*>\" (get-url (read-line)) \"\" 0))

Jeff

#1
Yes, by writing your own filesystem :)
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

hsmyers

#2
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
\"Censeo Toto nos in Kansa esse decisse.\"—D. Gale \"[size=117]ℑ♥λ[/size]\"—Toto

cormullion

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

DrDave

#4
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.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.

\"Getting Started with Erlang\"  version 5.6.2

hsmyers

#5
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
\"Censeo Toto nos in Kansa esse decisse.\"—D. Gale \"[size=117]ℑ♥λ[/size]\"—Toto

aron

#6
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">http://gnuwin32.sourceforge.net/packages/coreutils.htm
newLISP browser: (print (replace \"<[^>]*>\" (get-url (read-line)) \"\" 0))

hsmyers

#7
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
\"Censeo Toto nos in Kansa esse decisse.\"—D. Gale \"[size=117]ℑ♥λ[/size]\"—Toto

m35

#8
If your target is Windows, you could also wield the win32api directly through http://www.newlisp.org/downloads/newlisp_manual.html#import">(import).



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



http://vbnet.mvps.org/code/fileapi/filedatetime.htm">http://vbnet.mvps.org/code/fileapi/filedatetime.htm

hsmyers

#9
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.
\"Censeo Toto nos in Kansa esse decisse.\"—D. Gale \"[size=117]ℑ♥λ[/size]\"—Toto

m35

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

DrDave

#11
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.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.

\"Getting Started with Erlang\"  version 5.6.2