Does Total Commander have a date variable?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
PiotrMP006
Junior Member
Junior Member
Posts: 12
Joined: 2014-03-05, 09:15 UTC

Does Total Commander have a date variable?

Post by *PiotrMP006 »

Hi

Does Total Commander have a date variable?

I need a date variable in YYYYMMDDHHMMSS format for timestamp for 7z archives.
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Does Total Commander have a date variable?

Post by *Stefan2 »

PiotrMP006 wrote: 2023-02-08, 08:59 UTC
Does Total Commander have a date variable?


No.

PiotrMP006 wrote: 2023-02-08, 08:59 UTC
I need a date variable in YYYYMMDDHHMMSS format for timestamp for 7z archives.


Where? How? What do you do? Explain your use-case.




 
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Does Total Commander have a date variable?

Post by *beb »

PiotrMP006 wrote: 2023-02-08, 08:59 UTC I need a date variable in YYYYMMDDHHMMSS format for timestamp for 7z archives.

Code: Select all

@echo off
REM runtime variables parsing
Setlocal EnableDelayedExpansion

REM date/time variables:
:: date !d! is yyyymmdd
for /f "tokens=1-3 delims=:,./- " %%g in ("%date%") do set d=%%i%%h%%g
:: time  !t! is hhmmssms
:: for /f "tokens=1-4 delims=:,./-"  %%g in ("%time%") do set t=%%g & set t=!t: =0! & set t=!t:~,2!%%h%%i%%j
:: time  !t! is hhmmss
for /f "tokens=1-4 delims=:,./-"  %%g in ("%time%") do set t=%%g & set t=!t: =0! & set t=!t:~,2!%%h%%i

REM archiving
7z.exe a TargetArchive_!d!!t!.zip .\SourceFolder\* -tzip -aoa -mmt -ssw -stl -ssp -y -mx9
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6495
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Does Total Commander have a date variable?

Post by *Horst.Epp »

Here a modified version and a example button.
Creates a 7z archive of the current source dir in the target dir.
The archive is named according to the source dir with the date and time added.

A sample button

Code: Select all

TOTALCMD#BAR#DATA
C:\TEMP\Test\f1\test.cmd
%T\%B %P
C:\WINDOWS\System32\imageres.dll,-68
test


-1
Here the cmd for it

Code: Select all

@echo off
REM runtime variables parsing
Setlocal EnableDelayedExpansion

REM date/time variables:
:: date !d! is yyyymmdd
for /f "tokens=1-3 delims=:,./- " %%g in ("%date%") do set d=%%i%%h%%g
:: time  !t! is hhmmssms
:: for /f "tokens=1-4 delims=:,./-"  %%g in ("%time%") do set t=%%g & set t=!t: =0! & set t=!t:~,2!%%h%%i%%j
:: time  !t! is hhmmss
for /f "tokens=1-4 delims=:,./-"  %%g in ("%time%") do set t=%%g & set t=!t: =0! & set t=!t:~,2!%%h%%i

REM archiving
"C:\Program Files\7-Zip\7z.exe" a %1_!d!!t!.7z %2* -aoa -mmt -ssw -stl -ssp -y -mx9

Windows 11 Home x64 Version 23H2 (OS Build 22631.3527)
TC 11.03 x64 / x86
Everything 1.5.0.1373a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.73
QAP 11.6.3.2 x64
hi5
Power Member
Power Member
Posts: 551
Joined: 2012-11-03, 11:35 UTC
Contact:

Re: Does Total Commander have a date variable?

Post by *hi5 »

Poll Date/time as new Parameters for Button bar, user cmd - viewtopic.php?t=75669
F4MiniMenu (Forum) - Open selected file(s) from TC in defined editor(s) - A (minimalistic) clone of F4Menu
Source at GitHub (AutoHotkey). TCSyncComments (copy file comments)
NotNull
Senior Member
Senior Member
Posts: 269
Joined: 2019-11-25, 20:43 UTC
Location: NL

Re: Does Total Commander have a date variable?

Post by *NotNull »

%date% and %time% are localized and depend on settings.
For example Americans use 12-31-2022; I use 31-12-2022.

A more universal approach:

Code: Select all

@echo off & setlocal
for /f "tokens=2 usebackq delims=.=" %%x in (`wmic os get  LocalDateTime /format:list ^|findstr "="`) Do set "NOW=%%x"

echo Current local time : %NOW%


Resulting in:

Code: Select all

Current local time : 20230208211109
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Does Total Commander have a date variable?

Post by *beb »

NotNull wrote: 2023-02-08, 20:11 UTC A more universal approach:
...
@NotNull
Thank you.
Looks quite a pretty one to me.

Alas, as they say: "The WMI command-line (WMIC) utility is deprecated as of Windows 10, version 21H1, and as of the 21H1 semi-annual channel release of Windows Server. This utility is superseded by Windows PowerShell for WMI (see Chapter 7—Working with WMI). This deprecation applies only to the WMI command-line (WMIC) utility..."
Still works, though (and hope will for sometime yet).

NB different output:

Code: Select all

@echo off
REM runtime variables parsing
Setlocal EnableDelayedExpansion
wmic os get LocalDateTime /format:list
echo Current local time
echo:
for /f "tokens=2 delims=.=" %%x in ('wmic os get LocalDateTime /format:list ^|findstr "="') do set "now=%%x"
echo tc ghisler board:     yyyymmddhhmmss
echo "date/time":          %now%
::                          20230210100947
echo:
for /f "tokens=2 delims==+" %%x in ('wmic os get LocalDateTime /format:list ^|findstr "="') do set "c=%%x" & set d=!c:.=! & set d=!d:~,17!
echo custom:               yyyymmddhhmmssms
echo date/time full:       !c!
::                          20230210100947.876000
echo date/time trim:       !c:~,-3!
::                          20230210100947.876
echo date/time no dot:     !d!
::                          20230210100947876
echo date only:            !d:~,8!
::                          20230210
echo time without ms:      !d:~8,6!
::                          100947
echo time with ms no dot:  !d:~8!
::                          100947876
echo time with ms and dot: !c:~8,10!
::                          100947.876
echo:
:: wait 7 seconds then exit
@echo wait a bit
ping -n 8 ::1 >nul
exit/b

:: https://ghisler.ch/board/viewtopic.php?t=78412
:: https://ghisler.ch/board/viewtopic.php?p=426930
:: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmic
:: https://ss64.com/nt/wmic.html
:: https://ss64.com/nt/syntax-substring.html
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
Stiltzkin
Member
Member
Posts: 182
Joined: 2004-09-10, 17:15 UTC

Re: Does Total Commander have a date variable?

Post by *Stiltzkin »

for a quick solution with winrar:

Code: Select all

TOTALCMD#BAR#DATA
%comspec% /c
rar.exe a -os -vt -m3 -tl -ep1 -ag" [YYYY-MM-DDTHHMMSS]" "%T%O.rar" %P%N
TOTALCMD64.EXE,8
rar.exe [YYYY-MM-DDTHHMMSS] %T%O.rar
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Does Total Commander have a date variable?

Post by *beb »

Shorter and more human-readable powershell based option for getting date and time in windows cmd:
example.cmd

Code: Select all

@echo off
REM runtime variables parsing
Setlocal EnableDelayedExpansion
echo getting date/time (in specific output format)
echo:
for /f "delims=" %%# in ('powershell get-date -format "{yyyy-MM-dd HH:mm}"') do set d=%%#
echo yyyy-MM-dd HH:mm
echo !d!
echo:
for /f "delims=" %%# in ('powershell get-date -format "{yyyy-MM-dd HH:mm:ss}"') do set d=%%#
echo yyyy-MM-dd HH:mm:ss
echo !d!
echo:
for /f "delims=" %%# in ('powershell get-date -format "{yyyyMMdd_HHmm}"') do set d=%%#
echo yyyyMMdd_HHmm
echo !d!
echo:
for /f "delims=" %%# in ('powershell get-date -format "{yyyy-MM-dd HH:mm:ss.fff}"') do set d=%%#
echo yyyy-MM-dd HH:mm:ss.fff (with milliseconds)
echo !d!
echo:
for /f "delims=" %%# in ('powershell get-date -format "{yyyy-MM-dd HH:mm:ss.ffff}"') do set d=%%#
echo yyyy-MM-dd HH:mm:ss.ffff (with 4-digit millisecond)
echo !d!
echo:
Date/time format options (a file name/path-friendly representation of the current date and time in 24-hour format; case-sensitive):

Code: Select all

yyyyMMddTHHmmssffff
yyyy  4-digit year
MM    2-digit month
dd    2-digit day
T     letter T as a [common] time separator [if needed]
HH    2-digit hour
mm    2-digit minute
ss    2-digit second
ffff  4-digit millisecond (f, ff, fff for 1/10, 1/100, and millisecond)
And getting back to the OP's request, making 7z archives with YYYYMMDDHHMMSS timestamp format:

Code: Select all

@echo off
REM runtime variables parsing
Setlocal EnableDelayedExpansion
REM date/time variables:
for /f "delims=" %%d in ('powershell get-date -format "{yyyyMMddHHmmss}"') do set d=%%d
REM archiving:
7z.exe a TargetArchive_!d!.zip .\SourceFolder\* -tzip -aoa -mmt -ssw -stl -ssp -y -mx9
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
Fla$her
Power Member
Power Member
Posts: 2317
Joined: 2020-01-18, 04:03 UTC

Re: Does Total Commander have a date variable?

Post by *Fla$her »

PiotrMP006 wrote: 2023-02-08, 08:59 UTCfor timestamp for 7z archives.
This doesn't require a variable. The archive will be created with the current date anyway. And if the date needs to be set according to the last modified file, then the -stl key is used.

beb wrote: 2023-02-27, 12:45 UTC Shorter and more human-readable powershell based
I don't know why you decided that the question is about the name of the archive, but speed is much more important than readability, and powershell slows down a lot at the first start. I would use nircmd and 7zG to see the normal progress of packaging in the GUI rather than the console window:

Code: Select all

TOTALCMD#BAR#DATA
%COMMANDER_PATH%\Progs\NirCmd\nircmd.exe exec min "%COMMANDER_PATH%\Progs\7-Zip\7zG.exe" a "~$currdate.yyyyMMdd$~$currtime.HHmmss$.7z" -mx -m0=LZMA2:fb273 -m1=LZMA2:lc4 -scsUTF-16LE -y
@"%WL"
wcmicons.dll,30
Pack selected to <yyyyMMddHHmmss>.7z
Overquoting is evil! 👎
Post Reply