Toolbar button to switch path by current date

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
jenka1980
New Member
New Member
Posts: 1
Joined: 2018-05-16, 08:13 UTC

Toolbar button to switch path by current date

Post by *jenka1980 »

Hello,

I have a log directories which created by dates e.g. "D:\Logs\0516" (for 16 in May).

I tried to create a button to switch source tab to this log directory.
First I used the CD command like so:

Code: Select all

CD D:\Logs\%date:~4,2%%date:~7,2%
But this only opens the "D:\Log" directory.

Then I tried using this command:

Code: Select all

%COMMANDER_PATH%\TOTALCMD64.exe /O /L="D:\Logs\%date:~4,2%%date:~7,2%"
This one also didn't help as it switches the left tab to the "D:\Log" directory.
Executing the same command from windows command prompt opens the full path in left tab "D:\Log\0516"

May be I'm doing something wrong and there is an other way to achieve my goal.
Hope you could help my
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48077
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

The %date:~4,2%%date:~7,2% substitution is done by cmd.exe, not by Windows. Try calling cmd.exe calling totalcmd64.exe.
Author of Total Commander
https://www.ghisler.com
User avatar
Stefan2
Power Member
Power Member
Posts: 4157
Joined: 2007-09-13, 22:20 UTC
Location: Europa

VBScript: SendMessage (switch to defined folder plus Date)

Post by *Stefan2 »

I don't get that to work and my lunch break is over:

SET myDate=0516 && setLocal EnableDelayedExpansion && %%Commander_EXE%% /O /L="c:\Temp\TC\LOGS\!myDate!"

any help?





Instead I would use a VBScript:

Code: Select all

'// TotalCommander VBScript to switch current path
'// Found at https://ghisler.ch/board/viewtopic.php?p=341233#341233
'// - - - To use create an button like:
'// - - - 	Command = "%COMMANDER_PATH%\TOOLs\CMDs\Switch to folder current date.VBS"
'// - - - 	Parameters =
'// - - - 	Start path =
'// - - - 	Icon = C:\windows\System32\WScript.exe,2
'// - - - 	Tool tip = Switch to LOGS folder of current date

'//-------------------------------------------------------- USER SETTINGS
v_BasePath 	= "c:\Temp\TC\LOGS\"
v_Month 	= Right("0"&Month(Now),2)
v_Day 		= Right("0"&Day(Now),2)
v_PATH		= v_BasePath  & "\" & v_Month & v_Day 

'//-------------------------------------------------------- THE CODE
'//Switch to other (inactive) panel
'cm_FocusTrg=4006;Focus on target file list
SendMessage "Total Commander",1075,4006,0

'// SET FOCUS to address field
'cm_EditPath=2912;Edit path field above file list
SendMessage "Total Commander",1075,2912,0

'// SEND KEYs
'https://ss64.com/vb/sendkeys.html
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys v_PATH   & "{ENTER}"

'//-------------------------------------------------------- HELPER function
'VBScript SendMessage 'http://demon.tw/copy-paste/vbs-sendmessage.html 'BY Coo_boi
Function SendMessage(lpWinTitle,wMsg,wParam,lParam)
	Dim WordApp,ShApp,colTask,oTask
	Set WordApp=CreateObject("Word.Application")
	Set colTask=wordapp.Tasks
	SendMessage=False
	For Each oTask In colTask
		If oTask.Visible And InStr(oTask.Name,lpWinTitle) Then
			oTask.SendWindowMessage wMsg,wParam,lParam
			SendMessage=True
			Exit For 
		End If
	Next
	WordApp.Quit
	Set WordApp=Nothing
End Function
'//--------------------------------------------------------




 
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6480
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Post by *Horst.Epp »

I use Nirsofts Nircmd for such function.
http://www.nirsoft.net/utils/nircmd.html

For your case make a button with the following em_command:

[em_CDToLog]
cmd=c:\tools\NirSoft\x64\nircmd.exe exec show %COMMANDER_EXE% /O /L=D:\logs\~$currdate.MMdd$

You have to adjust the path of your nircmd.exe of course.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3447)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.73
QAP 11.6.3.2 x64
User avatar
Stefan2
Power Member
Power Member
Posts: 4157
Joined: 2007-09-13, 22:20 UTC
Location: Europa

NirCmd switch to folder of current date

Post by *Stefan2 »

Horst.Epp wrote:I use Nirsofts Nircmd
nircmd in combination with TCs command line options is the best way, :thumbsup:





 
User avatar
petermad
Power Member
Power Member
Posts: 14793
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

This button should do it:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C %COMMANDER_EXE% /O /S /L="D:\Logs\%date:~4,2%%date:~7,2%"

%COMMANDER_EXE%,6
Open D:\Logs\date


-1
To make the button:
1. Mark the green text above (including TOTALCMD#BAR#DATA in the first line and -1 in the last line).
2. Copy it to the ClipBoard (Ctri+C).
3. Right click on TC's buttonbar and choose "Paste".
Note - for other users:
~4,2 and ~7,2 has to match the current locale - Under Danish Windows it would for example be ~0,2 and ~3,2 to match 1605 (sixteenth of may). Type: DATE in a command prompt to see the format on your system.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6480
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Post by *Horst.Epp »

petermad wrote:This button should do it:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C %COMMANDER_EXE% /O /S /L="D:\Logs\%date:~4,2%%date:~7,2%"

%COMMANDER_EXE%,6
Open D:\Logs\date


-1
To make the button:
1. Mark the green text above (including TOTALCMD#BAR#DATA in the first line and -1 in the last line).
2. Copy it to the ClipBoard (Ctri+C).
3. Right click on TC's buttonbar and choose "Paste".
Note - for other users:
~4,2 and ~7,2 has to match the current locale - Under Danish Windows it would for example be ~0,2 and ~3,2 to match 1605 (sixteenth of may). Type: DATE in a command prompt to see the format on your system.
My date format shows 16.05.2018 for today (German Locale)
Therefore changed your button to %date:~3,2%%date:~0,2%
But I prefer the Nircmd solution which works independent of any locale
and also doesn't show a cmd window while executing
Windows 11 Home x64 Version 23H2 (OS Build 22631.3447)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.73
QAP 11.6.3.2 x64
User avatar
petermad
Power Member
Power Member
Posts: 14793
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

also doesn't show a cmd window while executing
Use this in stead to minimize the cmd window.

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C %COMMANDER_EXE% /O /S /L="D:\Logs\%date:~4,2%%date:~7,2%"

%COMMANDER_EXE%,6
Open D:\Logs\date

1
-1
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Post Reply