Author Topic: Change the timestamp of a file  (Read 357 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 12940
  • Assembler is fun ;-)
    • MasmBasic
Change the timestamp of a file
« on: August 18, 2022, 07:01:33 AM »
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


Code: [Select]
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

  • Member
  • ****
  • Posts: 664
Re: Change the timestamp of a file
« Reply #1 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?)

Tsk tsk ...

"But your honor, I swear I wrote that document before I knew that Global Enterprises' stock was gonna crash!"

Vortex

  • Member
  • *****
  • Posts: 2697
Re: Change the timestamp of a file
« Reply #2 on: August 18, 2022, 05:23:41 PM »
Hi NoCforMe,

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

  • Moderator
  • Member
  • *****
  • Posts: 12940
  • Assembler is fun ;-)
    • MasmBasic
Re: Change the timestamp of a file
« Reply #3 on: August 18, 2022, 06:27:53 PM »
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

  • Member
  • ****
  • Posts: 664
Re: Change the timestamp of a file
« Reply #4 on: August 19, 2022, 05:45:45 AM »
[Foghorn Leghorn voice]
It was a, just a, it was just a joke, son.
[/Foghorn Leghorn voice]

NoCforMe

  • Member
  • ****
  • Posts: 664
Re: Change the timestamp of a file
« Reply #5 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.

(I didn't know that before reading the Quora article.)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 12940
  • Assembler is fun ;-)
    • MasmBasic
Re: Change the timestamp of a file
« Reply #6 on: August 19, 2022, 07:54:52 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?
Quote
Open "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:
Quote
Touch 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

  • Member
  • ****
  • Posts: 664
Re: Change the timestamp of a file
« Reply #7 on: August 19, 2022, 08:23:06 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.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 12940
  • Assembler is fun ;-)
    • MasmBasic
Re: Change the timestamp of a file
« Reply #8 on: August 19, 2022, 08:34:31 AM »
See The Unix Hater's Handbook.

Lovely :tongue:

Quote
Sure It Corrupts Your Files,
But Look How Fast It Is!

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

Quote
If 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

  • Member
  • ****
  • Posts: 664
Re: Change the timestamp of a file
« Reply #9 on: August 19, 2022, 09:16:52 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.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 12940
  • Assembler is fun ;-)
    • MasmBasic
Re: Change the timestamp of a file
« Reply #10 on: August 19, 2022, 09:56:44 AM »
In my first year at university, I actually worked with 80-column punch cards :cool:

Vortex

  • Member
  • *****
  • Posts: 2697
Re: Change the timestamp of a file
« Reply #11 on: August 19, 2022, 06:22:24 PM »
Hi NoCforMe,

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

  • Member
  • ****
  • Posts: 664
Re: Change the timestamp of a file
« Reply #12 on: August 20, 2022, 05:55:27 AM »
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.