File Info Output: Can I Restate Modification Date & Time?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
raywood
Posts: 11
Joined: 20 Jan 2020 20:28

File Info Output: Can I Restate Modification Date & Time?

#1 Post by raywood » 03 Apr 2022 14:48

I am working on a batch script that gives me a recursive list of all files in a folder. Each line presents multiple bits of information about one file, including (in this order) last modified date and time, file size in bytes, file name. Example of output: 04/03/2022 03:00 PM 265 Filename.

I would like to rearrange the date and time information so that a sort of the list will use dates correctly in ascending order. In other words, I would like to change that example to read something like 2022-04-03 15:00 265 Filename.

I have a little familiarity with batch use of DATE and TIME commands for this purpose. But that's not relevant here. In this case, I'm looking to modify the output of the file's modification date and time, not the current system date and time. I'm not sure I have seen that done, and that's my question: is it feasible and, if so, where should I be looking for guidance in the appropriate syntax?

As an alternative, it is not terribly difficult to modify the list after the fact, in a spreadsheet. I am just hoping to automate the process in the batch command if that's possible.

aGerman
Expert
Posts: 4458
Joined: 22 Jan 2010 18:01
Location: Germany

Re: File Info Output: Can I Restate Modification Date & Time?

#2 Post by aGerman » 04 Apr 2022 11:16

Could you elaborate on how you currently generate this output?

Steffen

raywood
Posts: 11
Joined: 20 Jan 2020 20:28

Re: File Info Output: Can I Restate Modification Date & Time?

#3 Post by raywood » 05 Apr 2022 19:24

Yes. Thanks for asking. My post provides a writeup, with links to the sources that explained it to me. That post is at https://raywoodcockslatest.wordpress.co ... h-oneline/. (Sorry for the long URL. Unfortunately, the FAQs provide no guidance in using the link button in this composition window, nor any link to the guide that supposedly exists somewhere on this site.)

The key lines of code, generating the output, are as follows:

Code: Select all

for /r %%A in (*) do (
  for /f %%B in ('certutil -hashfile "%%A" SHA512 ^| find /V ":"') do echo %%~tA %%~zA %%B %%~fA >>%OUTFILE%
)
So that's where the output is coming from.

raywood
Posts: 11
Joined: 20 Jan 2020 20:28

Re: File Info Output: Can I Restate Modification Date & Time?

#4 Post by raywood » 09 Apr 2022 09:55

Bump

miskox
Posts: 421
Joined: 28 Jun 2010 03:46

Re: File Info Output: Can I Restate Modification Date & Time?

#5 Post by miskox » 09 Apr 2022 10:14

First option: replace "/" with "-" in the output file (looks like this character is in the date only).

Second option: rearange %%~tA to YYYY-MM-DD separately.

Saso

raywood
Posts: 11
Joined: 20 Jan 2020 20:28

Re: File Info Output: Can I Restate Modification Date & Time?

#6 Post by raywood » 16 May 2022 09:01

Thanks. I suspected that would be the solution.

I asked because, well, I had a friend who knew APL. In APL, you could launch a rocket to the Moon with a command that looked like ΦP→W?. Every now and then I see a bit of batch code that reminds me of that, where they do things I didn't know were possible.

Is it just me, or is there a lot less of that batch mastery these days? As I think of it, it's been a while since I saw much of it.

aGerman
Expert
Posts: 4458
Joined: 22 Jan 2010 18:01
Location: Germany

Re: File Info Output: Can I Restate Modification Date & Time?

#7 Post by aGerman » 16 May 2022 10:02

Whoa :shock: Apparently I totally lost track of this thread, sorry.
Is it just me, or is there a lot less of that batch mastery these days? As I think of it, it's been a while since I saw much of it.
I'm under the same impression. Batch is going to get kicked out by PowerShell.

Steffen

ShadowThief
Expert
Posts: 1087
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: File Info Output: Can I Restate Modification Date & Time?

#8 Post by ShadowThief » 16 May 2022 12:22

raywood wrote:
16 May 2022 09:01
Is it just me, or is there a lot less of that batch mastery these days? As I think of it, it's been a while since I saw much of it.
It's definitely moved to more of a hobby language from what I've seen, but there are still a couple of fairly active communities on Reddit and Discord.

raywood
Posts: 11
Joined: 20 Jan 2020 20:28

Re: File Info Output: Can I Restate Modification Date & Time?

#9 Post by raywood » 01 Jun 2022 18:59

Thanks for your feedback.

Early dabbling suggests you have to learn all of PowerShell to be sure you're using it correctly for anything. I've had several experiences of using scripts people recommended, only to find there's an exception requiring the additional WhoZit cmdlet if you wear a size 12 shoe.

For my purposes, Python is a more likely choice. It can actually teach me to start with "Hello, World!"

Take care ...

Post Reply