MRT: TODAY Date and date refreshing

English support forum

Moderators: sheep, Hacker, Stefan2, white

StatusQuo
Power Member
Power Member
Posts: 1465
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo » 2008-04-09, 18:35 UTC

StatusQuo wrote:I posted this into the script plugin thread, hoping to get a solution...
It's solved, an entry "ParseDirs=1" was missing in the [Now] section. So the INI should look like this to also work with directories:

Code: Select all

[Script]
Section=Now
;js
;Extension
;exe-arc up
;AddZeros

[Defaults]
LongName=1
ParseDirs=0

[Extension]
Script=ext.vbs

[AddZeros]
Script=AddZeros.vbs
LongName=0

[exe-arc up]
Script=Exeup.vbs
LongName=0

[js]
Script=java.js
LongName=0

[Now]
Script=Now.vbs
LongName=0
ParseDirs=1
2zuccadoc
Thanks for posting your settings.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!

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

Post by *Stefan2 » 2010-07-09, 20:02 UTC

sfdude wrote:Would somebody care to summarize the solution
http://www.ghisler.ch/board/viewtopic.php?p=206029#206029


1.) download script_wdx to C:\Temp
http://www.totalcmd.net/plugring/script_wdx.html



2.) Start your TC and go to C:\Temp, double click at "script_wdx_0.2.0.0.rar"
The plugin archive contains an "pluginst.inf" to automatically install this plugin.
- you will be asked if you want to install this plugin: [OK]
- install to "%Commander_Path%\Plugins\wdx\script": [OK]
- contain plugin list appears: [OK]
- Done



3.) Go to "%Commander_Path%\Plugins\wdx\script" folder
- create an new text.txt file in that folder
- copy the script from StatusQuo, found at http://www.ghisler.ch/board/viewtopic.php?p=146906#146906
into this text.txt file
- save (rename) this text.txt file to something with VBS extension: e.g. CurrentDate.vbs
So you have now "%Commander_Path%\Plugins\wdx\script\CurrentDate.vbs"



4.) - open "%Commander_Path%\Plugins\wdx\script\script.ini"
- add an new section
[CurrentDate]
Script=CurrentDate.vbs
LongName=0
ParseDirs=1



- and modify section
[Script]
Section=Extension

to
[Script]
Section=CurrentDate


so the plugin knows what script is to use.
Save the file "script.ini".



5.) Test:
- Select "C:\Temp\script_wdx_0.2.0.0.rar"
- press Ctrl+M
- in MRU click into that field where the date should be inserted into the filename: e.g. right behind [N]
- click on [ [=?]Plugin ]
- select "script" and "Result"
(or "Result1", or "Result2", or...)
You will see what happens.



Note:
In the var "content" is store what you will get by "Result", using the term "[=script.Result]"
The var "content1" you can access by "Result1", [=script.Result1]
... and so on
"content2" => [=script.Result2]
"content3" => [=script.Result3]
...
So you don't have to modify the last line in that script.


And, whit an little knowledge of VBScript you can adjust the time/date format yourself.



HTH? :D


----

I have rearranged StatusQuo's script for an other point of view:

Code: Select all

'///////////////////////////////////////////////////
' NOW v0.2b (W) StatusQuo 2008 - 2010
' small VBS-script for TC content plugin SCRIPT.WDX (http://www.totalcmd.net/plugring/script_wdx.html)
'///////////////////////////////////////////////////
' Purpose:
' Returns the current system date & time.
' Usage in MRT, Alt+F7 search etc.:
'///////////////////////////////////////////////////
'Basics:
myYear    = Year(Date) 
myMonth = Right("0" & Month(Date), 2)
myDay     = Right("0" & Day(Date), 2) 
myHour   = Left(Time, 2) 
myMinute = Mid(Time, 4, 2) 
mySecond = Right(Time, 2)  
myDateDelimiter = "."
myTimeDelimiter = ""
myDateTimeDelimiter = " - "

'Some default formats:
'YMD "script > Result1"
	content1 = myYear & myDateDelimiter & myMonth & myDateDelimiter & myDay
'DMY "script > Result2"
	content2= myDay & myDateDelimiter & myMonth & myDateDelimiter & myYear
'HHMMSS "script > Result3"
	content3 = myHour & myTimeDelimiter & myMinute & myTimeDelimiter & mySecond
'HHMM "script > Result4"
	content4 = myHour & myTimeDelimiter & myMinute
'YMD + HHMM "script > Result5"
	content5 = content1 &  myDateTimeDelimiter & content4
'Just set the default for "script > Result":
	content=content5
'More examples:
	content6 = "(" & content1 &  "_" & content4 & ")"
	content7 = "(" & content1 &  " at " & myHour & "," &  myMinute & ")"
Inofficial FAQs || WIKI (Deu/Eng) || TC Home (What's new? // FAQ // Download // Order // Addons // Tools // Plugins)
Erst wenn der letzte Baum gefällt oder die letzte Biene verendet ist, werden die Leute verstehen warum Umweltschutz wichtig ist.

zuccadoc
Junior Member
Junior Member
Posts: 20
Joined: 2008-03-14, 08:40 UTC

Post by *zuccadoc » 2011-08-08, 03:16 UTC

Hi Guys!

Now I works in the USA and I had some problems with the System Time AM/PM.

I decided to make something a little bit more user friendly...

Here my code:

Code: Select all

'/////////////////////////////////////////////////// 
' NOW v0.1 (W) StatusQuo 2008
' tuned by Zuccadoc 2011 
' small VBS-script for TC content plugin SCRIPT.WDX 
'/////////////////////////////////////////////////// 
' Purpose: 
' -------- 
' Returns the current system date & time. 
' Refeshs file like YMD_HmS_filename.ext or YMD_filename.ext or or HmS_filename.ext with the current system date & time. 
' Works also with system time AM/PM, it returns always the 24h format (@5:30:56 PM e.g. 173056)
' Remove date or time or both
' 
' Usage in MRT, Alt+F7 search etc.: 
' ----- 
' - install script plugin: http://www.totalcmd.net/plugring/script_wdx.html 
' - in script.ini (in the plugin-dir) include this file like this (without leading "'"): 
'[Now] 
'Script=Now.vbs 
'LongName=0
'ParseDirs=1
' 
' - in script.ini (again) change the file beginning to use the new section: 
'[Script] 
'Section=Now 
' 
' - to add date & time or refresh both or only date or only Time (YMD_HmS_filename.ext, e.g. 20081229_221957_filename.ext) enter in TC: 
'[=script.Result] 
' - to remove date or time or both use 
'[=script.Result1] 
' - to add/refresh only date and remove the time if it exists use 
'[=script.Result2] 
' - to add/refresh only time and remove the date if it exists use 
'[=script.Result3]  
'/////////////////////////////////////////////////// 
    
set re=new regexp
ch_DateTime=0

'Create Strings with Date and Time    

cur_date=Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & "_"                   ' YMD 
cur_time=Right("0" & Hour(Now), 2) &  Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2) & "_" ' HmS 

'remove extension from filename and build Filename if directory
if InStrRev(filename,".")>0 then
   sFN=Left(filename,InStrRev(filename,".")-1)
 else
   'if directory
   sFN=filename
End if

'Build Test Strings

Re_Date="(1|2)\d\d\d(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])"
Re_Time="(0\d|1\d|2[013])[012345]\d[012345]\d"

'Build check string
'0 No Date no time
'1 only time
'2 only Date
'3 Date and time

'check if YMD_
re.Pattern="^" & Re_Date & "_"
If re.test(sFN) then ch_DateTime=2 
'check if HmS_
re.Pattern="^" & Re_Time & "_"
If re.test(sFN) then ch_DateTime=1
'check if YMD_HmS_
re.Pattern="^" & Re_Date & "_" & Re_Time & "_"
If re.test(sFN) then ch_DateTime=3 

'Now Action!

Select Case ch_DateTime
 case 0
    content=cur_date & cur_time & sFN
    content1=sFN
    content2=cur_date & sFN
    content3=cur_time & sFN
 case 1
    fFN=Right(sFN, Len(sFN)-7)
    content=cur_time & fFN
    content1=fFN
    content2=cur_date & fFN
    content3=cur_time & fFN
 case 2
    fFN=Right(sFN, Len(sFN)-9)
    content=cur_date & fFN
    content1=fFN
    content2=cur_date & fFN
    content3=cur_time & fFN
 case 3
    fFN=Right(sFN,Len(sFN)-16)
    content=cur_date & cur_time & fFN
    content1=fFN
    content2=cur_date & fFN
    content3=cur_time & fFN
End select
Enjoy.
I follow the truth.

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

Post by *Stefan2 » 2014-02-21, 22:08 UTC

Based on discussion like

Arbitrary number system for counter in multi-rename-tool
http://ghisler.ch/board/viewtopic.php?t=39372

Jede n. Datei markieren
http://ghisler.ch/board/viewtopic.php?t=39364


I have thought this plugin could be of aid, and made some Proof Of Concept scripts:

Here I utilize the Registry to store the value for every next file (as the scripts are executed once for every file)

NOTE: you have to add the registry key yourself FIRST, and always adjust the start value!!!

Not nice, but it seems to work.



Counter_Numbers.vbs

Code: Select all

'=====================================================
'Script Content plugin 0.2 'Lev Freidin (c) 2005-2008
'http://ghisler.ch/board/viewtopic.php?p=206065#206065
'=====================================================

' add increasing number as counter

RegKey    = "HKEY_CURRENT_USER\Software\aTCSCRIPT\counter"
'//  FIRST DO THIS YOURSELF:
'// Add the key "aTCSCRIPT" to the registry below of "HKEY_CURRENT_USER\Software\" yourself
'// Below    of "aTCSCRIPT" key, add a new string named "Counter"
'// For "Counter" add the wanted start value, like  '1'

'some VBScript basics:
Set WSC   = CreateObject("WScript.Shell")

'read value from RegKey:
LastCount = WSC.RegRead(RegKey)

'-----------------------------------------------
'do something with that LastCount, if wanted:
'for example pad it:
PaddingLength = 4
NewCount = string(PaddingLength - Len(LastCount), "0") & LastCount
'-----------------------------------------------

'use the result for "content" of "Script Content Plugin 0.2.0.0"
content   = NewCount
'in TCs MRT or Custom Columns use "[=script.Result]" to get the value of the above "content"

'increase the value and write it back to the store:
NextCount = NewCount + 1
WSC.RegWrite RegKey, NextCount , "REG_SZ"

'=====================================================




Counter_AZ.vbs

Code: Select all

'=====================================================
'Script Content plugin 0.2 'Lev Freidin (c) 2005-2008
'http://ghisler.ch/board/viewtopic.php?p=206065#206065
'=====================================================

'Use 'A' to 'Z' as counter

'of course, this code should be improved to add counters like'AAA', 'AAB', 'AAC',...


RegKey    = "HKEY_CURRENT_USER\Software\aTCSCRIPT\counter"
'//  FIRST DO THIS YOURSELF:
'// Add the key "aTCSCRIPT" to the registry below of "HKEY_CURRENT_USER\Software\" yourself
'// Below    of "aTCSCRIPT" key, add a new string named "Counter"
'// For "Counter" add the wanted start value, like  '65' for 'A' 
'//         (see an ASCII table, like at http://www.asciitable.com/)

'some VBScript basics:
Set WSC   = CreateObject("WScript.Shell")

'read value from RegKey:
LastCode = WSC.RegRead(RegKey)

'-----------------------------------------------
'do something with that LastCount, if wanted:
'e.g. change the number to a character:
Char = chr(LastCode)
'-----------------------------------------------

'use the result for "content" of "Script Content Plugin 0.2.0.0"
content   = Char
'in TCs MRT or Custom Columns  use "[=script.Result]" to get the value of the above "content"

'increase the value and write it back to the store:
NextCode = LastCode + 1
If NextCode > 90 Then NextCode = 65
WSC.RegWrite RegKey, NextCode , "REG_SZ"

'=====================================================


Counter_EveryNth.vbs
- install and configure the script plugin
- add custom column with '[=script.Result]'
- click on header of that column to sort and get all marked files together

Code: Select all

'=====================================================
'Script Content plugin 0.2 'Lev Freidin (c) 2005-2008
'http://ghisler.ch/board/viewtopic.php?p=206065#206065
'=====================================================

' add increasing number as counter

RegKey    = "HKEY_CURRENT_USER\Software\aTCSCRIPT\counter"
'//  FIRST DO THIS YOURSELF:
'// Add the key "aTCSCRIPT" to the registry below of "HKEY_CURRENT_USER\Software\" yourself
'// Below    of "aTCSCRIPT" key, add a new string named "Counter"
'// For "Counter" add the wanted start value, like  '1'

'some VBScript basics:
Set WSC   = CreateObject("WScript.Shell")

'read value from RegKey:
LastCount = WSC.RegRead(RegKey)

'-----------------------------------------------
'do something with that LastCount, if wanted:
'for example choose every second:
SelectEvery = 3 'th
If (LastCount mod SelectEvery < 1) Then
    content   = SelectEvery & " 'th"
End If

'use the result for "content" of "Script Content Plugin 0.2.0.0"
'in TCs Custom Columns  use "[=script.Result]" to get the value of the above "content"
'then click at the column header to sort, and have all marked files together
'-----------------------------------------------

'increase the value and write it back to the store:
NextCount = LastCount + 1
WSC.RegWrite RegKey, NextCount , "REG_SZ"

'=====================================================

Code: Select all

Name | Ext | Count
a1.txt
a2.txt
a3.txt       3 'th
a4.txt
a5.txt
a6.txt       3 'th
a7.txt
a8.txt
a9.txt       3 'th

Code: Select all

Name | Ext | Count
a3.txt       3 'th
a6.txt       3 'th
a9.txt       3 'th
a1.txt
a2.txt
a4.txt
a5.txt
a7.txt
a8.txt

Please improve them and share with the community :D

zuccadoc
Junior Member
Junior Member
Posts: 20
Joined: 2008-03-14, 08:40 UTC

Post by *zuccadoc » 2016-02-09, 19:12 UTC

All right, unfortunately this Plugin development is dead and there is no x64 Version. Since I need just basically two features:

1) Append "YYYYMMDD@HHmmSS_" to the filename
2) Refresh the time stamp on file already renamed

on single files, I decided to write a .cmd batch file (Stampme_Zuk.cmd):

Please check/remove the spaces at the line ends if you copy paste the code below. See posts below for details!

Code: Select all

@ECHO off
  SETLOCAL
  IF [%1] NEQ [] goto s_start

  :: Author - Simon Sheppard, Nov 2014
  :: Modified by Zucca, Feb 2016
  :: Tested for Windows XP Pro or greater
  Echo StampMe.cmd
  Echo Rename a file with the DATE/Time
  Echo:
  Echo Syntax
  Echo    STAMPME TestFile.txt
  Echo:
  Echo    STAMPME "Test File.txt"
  Echo:
  Echo    STAMPME "c:\docs\Test File.txt"
  Echo:
  Echo    Will rename the file in the format "20141230@165501_Test File.txt"
  Echo:
  Echo    NOTE:
  Echo    The script refresh only date and time if the filename matches the mask:
  Echo    2XXXXXXX@XXXXXX_"rest filename"
  Echo:
  Echo    In a batch file use CALL STAMPME ...
 
  GOTO :eof
 
  :s_start
  Set _file=%~n1%
  Set _pathname=%~f1%
  Set _ext=%~x1%
 
  :: If mask 2XXXXXXX@XXXXXX_"filename" is matched then refresh only date and time
  If "%_file:~0,1%" equ "2" If "%_file:~8,1%" equ "@" If "%_file:~15,1%" equ "_" Set _file=%_file:~16%
  
  :: Get the date/time
  FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO Set _DTS=%%a
  Set _datetime=%_DTS:~0,4%%_DTS:~4,2%%_DTS:~6,2%@%_DTS:~8,2%%_DTS:~10,2%%_DTS:~12,2%

  :: Echo   YearMMDay@HRMinSec
  :: Echo   %_datetime%
 
  :: Rename the file
  REN "%_pathname%" "%_datetime%_%_file%%_ext%"

  If errorlevel 1 (
   :: REN is Impossible
   CLS
   :: change background color to Red and font color to bright yellow
   color 4E
   echo Doh!
   echo.  
   echo.
   echo File:
   echo.
   echo %~n1%
   echo.
   echo cannot be renamed!!!
   echo.  
   echo.  
   ::Pause
   pause
  )
I use it in TC with the following user command (from usercmd.ini):

Code: Select all

[em_StampMe]
button=
cmd=StampMe_Zuk.cmd
param=%P%N
path=%COMMANDER_PATH%\Batch\

Very pleased with the result, so I share this.
Last edited by zuccadoc on 2016-02-11, 08:42 UTC, edited 2 times in total.
I follow the truth.

User avatar
tuska
Power Member
Power Member
Posts: 1619
Joined: 2007-05-21, 12:17 UTC

Post by *tuska » 2016-02-10, 10:36 UTC

Hi,
I have tried it.

bbb.txt --> 20160210@113209 _bbb .txt
There is a space after the time and before the extension.
Could they be avoided?

I could not get the following:
Refresh the time stamp on file already renamed

After a second renaming I get:
20160210@113501 _20160210@113209 _bbb .txt

Could you please check. Thank you!
Gruß,
Karl

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

Post by *Horst.Epp » 2016-02-10, 11:22 UTC

The ShimExt utility makes it much easier.
http://www.8charmax.com/shimext/

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

Touch stamp file with current date.

Post by *Stefan2 » 2016-02-10, 12:24 UTC

zuccadoc wrote: :: Get the date/time
FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO Set _DTS=%%a
Set _datetime=%_DTS:~0,4%%_DTS:~4,2%%_DTS:~6,2%@%_DTS:~8,2%%_DTS:~10,2%%_DTS:~12,2%
That's cool using WMI (taken from ss64.com?). No need anymore for padding with zeros'!

- - -
tuska wrote:There is a space after the time and before the extension.
Not for me, and I can't spot from the batch either, from where this spaces should come.

20160210@131843_bbb.txt
20160210@132403_bbb.txt


Be sure to have no spaces here around the equal sign:

Code: Select all

  Set _file=%~n1%
  Set _pathname=%~f1%
  Set _ext=%~x1% 
-
tuska wrote:I could not get the following:
That is related to your above stated problem with additional space.
So the "If mask" query will not match.

20160210@132543_20160210@132403 _bbb .txt


 
Inofficial FAQs || WIKI (Deu/Eng) || TC Home (What's new? // FAQ // Download // Order // Addons // Tools // Plugins)
Erst wenn der letzte Baum gefällt oder die letzte Biene verendet ist, werden die Leute verstehen warum Umweltschutz wichtig ist.

User avatar
tuska
Power Member
Power Member
Posts: 1619
Joined: 2007-05-21, 12:17 UTC

Post by *tuska » 2016-02-10, 15:52 UTC

@Stefan2
Thank you for your hint - now I get it.
I didn't state that after copy/paste (code from thread to file) in almost all lines in the file blanks at the end of line were automatically appended.
After removing these blanks all works fine now.

@Horst.Epp
Thank you for the link - sounds interesting for me - will try it!
Gruß,
Karl

zuccadoc
Junior Member
Junior Member
Posts: 20
Joined: 2008-03-14, 08:40 UTC

Post by *zuccadoc » 2016-02-11, 08:36 UTC

tuska wrote:@Stefan2
Thank you for your hint - now I get it.
I didn't state that after copy/paste (code from thread to file) in almost all lines in the file blanks at the end of line were automatically appended.
I can reproduce this. I tried to edit my previous post, but it looks clean. I don´t know what is going on.

I put a warning advice in the meanwhile.
I follow the truth.

Post Reply