Toolbar button to switch path by current date

English support forum

Moderators: sheep, Hacker, Stefan2, white

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 » 2018-05-16, 08:30 UTC

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: 37006
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2018-05-16, 10:33 UTC

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
http://www.ghisler.com

User avatar
Stefan2
Power Member
Power Member
Posts: 2356
Joined: 2007-09-13, 22:20 UTC
Location: Europa

VBScript: SendMessage (switch to defined folder plus Date)

Post by *Stefan2 » 2018-05-16, 11:21 UTC

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: 3225
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Post by *Horst.Epp » 2018-05-16, 11:42 UTC

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 10 Home x64 October 2018 Update, Version 1809 (OS Build 17763.379)
Intel(R) Core(TM) i7-4770 CPU @ 3.40GH, 16GB RAM
TC 9.22 x64 and x86, Everything 1.4.1.939 (x64)

User avatar
Stefan2
Power Member
Power Member
Posts: 2356
Joined: 2007-09-13, 22:20 UTC
Location: Europa

NirCmd switch to folder of current date

Post by *Stefan2 » 2018-05-16, 12:17 UTC

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: 8201
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, Denmark
Contact:

Post by *petermad » 2018-05-16, 15:34 UTC

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
Danish Total Commander Translator
TC 9.21a 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 64bit and TC 2.92b1 on Android 6.0
Get: Extended Total Commander Menus | PHSM-Calendar

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

Post by *Horst.Epp » 2018-05-16, 16:00 UTC

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 10 Home x64 October 2018 Update, Version 1809 (OS Build 17763.379)
Intel(R) Core(TM) i7-4770 CPU @ 3.40GH, 16GB RAM
TC 9.22 x64 and x86, Everything 1.4.1.939 (x64)

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

Post by *petermad » 2018-05-16, 21:57 UTC

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
Danish Total Commander Translator
TC 9.21a 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 64bit and TC 2.92b1 on Android 6.0
Get: Extended Total Commander Menus | PHSM-Calendar

Post Reply