C:\_G\WWW\~ELISANET\INFO\tscmd193.html
<https://www.salminet.fi/info/tscmd193.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Tue 11-Aug-2026 16:49:47

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



193} Getting the last modified datestamp of a file using PowerShell-aided command-line

  @echo off & setlocal enableextensions
  call :GetFileModifiedDateTimeSingle "%~1" datetimestamp_
  echo.
  echo %datetimestamp_% %~1
  echo.
  ::
  call :GetFileModifiedDateTimeParsed "%~1" wd_ HH_ MN_ ss_ dd_ MM_ yyyy_
  echo wd_=%wd_%
  echo HH_=%HH_%
  echo MN_=%MN_%
  echo ss_=%ss_%
  echo dd_=%dd_%
  echo MM_=%MM_%
  echo yyyy_=%yyyy_%
  echo.
  ::
  echo %wd_% %dd_%.%MM_%.%yyyy_% %HH_%:%MN_%:%ss_%
  endlocal & goto :EOF

  :: The indentation is essential to avoid incorrect syntax
  :GetFileModifiedDateTimeSingle
  setlocal enableextensions
  set file_=%~1
  for /f "usebackq delims=" %%a in (`powershell -command ^
    "(Get-Item '%file_%').LastWriteTime.ToString('ddd yyyy-MM-dd HH:mm:ss')"`) do (
      set result_=%%a)
  endlocal & set "%2=%result_%" & goto :EOF

  :GetFileModifiedDateTimeParsed
  setlocal enableextensions
  set file_=%~1
  for /f "tokens=1-8 usebackq delims=-: " %%a in (`powershell -command ^
   "(Get-Item '%file_%').LastWriteTime.ToString('ddd HH:mm:ss dd-MM-yyyy')"`) do (
      set a_=%%a
      set b_=%%b
      set c_=%%c
      set d_=%%d
      set e_=%%e
      set f_=%%f
      set g_=%%g
      )
    endlocal & set "%2=%a_%" ^
      & set "%3=%b_%" & set "%4=%c_%" & set "%5=%d_%" ^
      & set "%6=%e_%" & set "%7=%f_%" & set "%8=%g_%" & goto :EOF

The output might be e.g.
  C:\_D\TEST>cmdfaq "C:\DIGIPHOTOS\Torig2026071701.JPG"

  Fri 2026-07-17 12:36:11 C:\DIGIPHOTOS\Torig2026071701.JPG

  wd_=Fri
  HH_=12
  MN_=36
  ss_=11
  dd_=17
  MM_=07
  yyyy_=2026

  Fri 17.07.2026 12:36:11

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd193.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd193
C:\_E\ARCZIP\COPYTONE.CMD /~info
https://www.salminet.fi/info/tscmd193.html
file:///c:/_g/www/~elisanet/info/tscmd193.html