News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Change the timestamp of a file

Started by jj2007, August 18, 2022, 07:01:33 AM

Previous topic - Next topic

jj2007

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Let esi=uCL$()                                ; Unicode, yeah!
  .if !Exist(esi)
        Inkey "usage: drag a file over the exe"
  .else
        Let edi=wRec$(GfDate$(-1)+", "+GfTime$(-1))
        Let edi=wInput$(wRec$("New date & time for "+esi+": "), edi)
        Inkey cfm$("\nAre you sure (y)?\n")
        .if eax=="y"
                Touch esi, TimeSF(Utf8$(edi))
                Inkey esi, " was touched"
        .else
                Inkey "The timestamp of ", esi, " was not changed"
        .endif
  .endif
EndOfCode


New date & time for "C:\Masm32\MasmBasic\Res\временная папка\Добро пожаловать.asc": 19.10.2020, 12:34:56

Are you sure (y)?
"C:\Masm32\MasmBasic\Res\временная папка\Добро пожаловать.asc" was touched


Note:
- the proposed string (19.10.2020, 12:34:56 in this case) shows the current timestamp
- you can edit the string using backspace, arrows, delete etc
- Explorer shows the change immediately, but you may have to refresh some other file managers
- file names in languages that don't work with your console will display garbled, but it works nonetheless

NoCforMe

So you're allowing users to lie about when a file was created? (or is that the last access time?)

Tsk tsk ...

"But your honor, I swear I wrote that document before I knew that Global Enterprises' stock was gonna crash!"
Assembly language programming should be fun. That's why I do it.

Vortex

Hi NoCforMe,

Quote from: NoCforMe on August 18, 2022, 12:37:03 PM
So you're allowing users to lie about when a file was created? (or is that the last access time?)

There are valid reasons to modify the time stamps of files :

https://www.quora.com/What-is-the-need-of-changing-time-stamps-of-a-file-in-Linux-In-which-circumstances-do-we-do-that

jj2007

NoCforMe,

I suggest that you file a case against Bill Gates :biggrin:

@Erol: Thanks. One of my common cases is to rearrange a set of files so that they appear in a particular order. My file manager displays files sorted by date - most recent on top (as a programmer, you know why). When I have a set of mp3 files that appears in "wrong" order, I just take the date of the last song in the album and add a second for all the others in the order I want. Works fine.

Another use: Sometimes I want to add comments to an old source without changing the timestamp. So I hold Shift and click on "Save as..." (in RichMasm, of course :cool:).

P.S.: I am pretty sure that judges in the EU know about SetFileTime :tongue:

NoCforMe

[Foghorn Leghorn voice]
It was a, just a, it was just a joke, son.
[/Foghorn Leghorn voice]
Assembly language programming should be fun. That's why I do it.

NoCforMe

So question for you: since this is a "touch" program, does it do this, which is part of the classic defined behavior of touch?

Quote
Some people prefer to use the touch command:

touch blank_file
This command produces an empty file if the file doesn't exist. Otherwise the timestamp is updated.

(I didn't know that before reading the Quora article.)
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on August 19, 2022, 05:50:20 AM
So question for you: since this is a "touch" program, does it do this, which is part of the classic defined behavior of touch?

Quote
Some people prefer to use the touch command:

touch blank_file
This command produces an empty file if the file doesn't exist. Otherwise the timestamp is updated.

Just try it :tongue:

Re "classic behaviour": which dialect?
QuoteOpen "U",#1, "test.txt"
Touch #1
Close #1

That was GfaBasic, 1987 for the Atari ST, later for Windows. MasmBasic Touch is simpler, although the old GfaBasic syntax will still work.

Linux touch:
QuoteTouch Command Options
-a, change the access time only
-c, if the file does not exist, do not create it
-d, update the access and modification times
-m, change the modification time only
-r, use the access and modification times of the file
-t, creates a file using a specified time

MasmBasic Touch "somefile.txt", TimeSF("24.12.2022, 17:30") (note that I ruthlessly opted for the European date syntax :badgrin:) would correspond to Linux' -t option:

# touch -c -t 12241730 somefile.txt

I wonder, though, what's the logic of touching a file that doesn't exist :cool:

NoCforMe

Quote from: jj2007 on August 19, 2022, 07:54:52 AM
I wonder, though, what's the logic of touching a file that doesn't exist :cool:

For that you'll have to ask one of those crazed Unix fanbois.

See The Unix Hater's Handbook.
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on August 19, 2022, 08:23:06 AMSee The Unix Hater's Handbook.

Lovely :tongue:

QuoteSure It Corrupts Your Files,
But Look How Fast It Is!

QuoteYou know the real trouble with Unix? The real trouble is that it became so popular. It wasn't meant to be popular. It was meant for a few folks working away in their labs, using Digital Equipment Corporation's old PDP-11 computer.

My first major program was a simulation of a complex heat pump written in Fortran IV on a PDP-11. I still remember that the printout was roughly 4-5 metres long, and that compiling it meant I could go for a coffee break :cool:

QuoteIf this book doesn't kill Unix, nothing will.
As for me? I switched to the Mac. No more grep, no more piping, no more
SED scripts. Just a simple, elegant life: "Your application has unexpectedly quit due to error number –1. OK?"

Donald A. Norman
Apple Fellow
Apple Computer, Inc.

And while I'm at it:
Professor of Cognitive Science, Emeritus
University of California, San Diego

NoCforMe

Quote from: jj2007 on August 19, 2022, 08:34:31 AM
My first major program was a simulation of a complex heat pump written in Fortran IV on a PDP-11. I still remember that the printout was roughly 4-5 metres long, and that compiling it meant I could go for a coffee break :cool:

[cue computer nostalgia]

Ah, kids today. Back when I was learning COBOL (business school) and FORTRAN (engineering school)*, our FORTRAN teacher told us about the good old days when he was a student. (People in the class were complaining about how loooong it took to get a program printout from the university computer center.)

"When I was a student, we coded on punch cards, 80-column cards. First you had to write your program, in longhand on 80-column coding sheets. You'd hand your stack of sheets into the first window at the computer center. After punching your source deck, they'd hand it to you, then you'd hand it in to the next window where they ran it through the compiler. If you had any compile errors, they handed you back the error deck so you could go and fix your mistakes. Otherwise if you were lucky you'd hand your object deck to the third window, where they'd run it. If you had any run-time errors ... ".

* Both on mainframes (Univac and Honeywell DPS-8) using time-share terminals (green-screen 80x25 or DEC typewriter terminals). High tech.
Assembly language programming should be fun. That's why I do it.

jj2007

In my first year at university, I actually worked with 80-column punch cards :cool:

Vortex

Hi NoCforMe,

Quote from: NoCforMe on August 19, 2022, 08:23:06 AM
For that you'll have to ask one of those crazed Unix fanbois.

See The Unix Hater's Handbook.

Checking the pdf :
Quote
Copyright  1994

The book is outdated. Plus, no reason to hate Unix and the Unix-like operating systems, that would be an unnecessary sentimental reaction.

NoCforMe

It's not so much the actual OS (and C and C++) that's to hate, it's the culture that grew up around it that's so well described in that document. Persists to this day, despite whatever advances have been made to correct all those problems pointed out there.

*nix? No thanks.
Assembly language programming should be fun. That's why I do it.