Write to file without changin Date modified

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
aron
Posts: 8
Joined: Fri May 12, 2006 2:28 am
Location: Sweden
Contact:

Write to file without changin Date modified

Post by aron »

Hi i use:

http://www.newlisp.org/downloads/newlis ... write-file

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

Can I do that in some way?

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

Yes, by writing your own filesystem :)
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

hsmyers
Posts: 104
Joined: Wed Feb 20, 2008 4:06 pm
Location: Boise, ID, USA
Contact:

Post by hsmyers »

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 "ℑ♥λ"—Toto

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Post by DrDave »

cormullion wrote: 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
Posts: 104
Joined: Wed Feb 20, 2008 4:06 pm
Location: Boise, ID, USA
Contact:

Post by hsmyers »

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 "ℑ♥λ"—Toto

aron
Posts: 8
Joined: Fri May 12, 2006 2:28 am
Location: Sweden
Contact:

Post by aron »

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

hsmyers
Posts: 104
Joined: Wed Feb 20, 2008 4:06 pm
Location: Boise, ID, USA
Contact:

Post by hsmyers »

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 "ℑ♥λ"—Toto

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm
Location: Carifornia

Post by m35 »

If your target is Windows, you could also wield the win32api directly through (import).

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

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

hsmyers
Posts: 104
Joined: Wed Feb 20, 2008 4:06 pm
Location: Boise, ID, USA
Contact:

Post by hsmyers »

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 "ℑ♥λ"—Toto

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm
Location: Carifornia

Post by m35 »

hsmyers wrote: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
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Post by DrDave »

m35 wrote:
hsmyers wrote: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

Locked