it works fine - after little correction - date (in Czech PC) is not 09.07.2009 but 9.7.2009.
Code: Select all
' http://ghisler.ch/board/viewtopic.php?t=45748
' VBS-Script to use with TotalCommander.
' _ForEachSelFileDo - Rename with date.vbs
' Purpose: add an date string to file name.
' choose between Created, Modified or Current time
' Usage: create the button, select one-or-more files, click the button, done.
'
' TotalCommander Button code:
' CMD: "%COMMANDER_PATH%\TOOLs\VBS\ForEachSelFileDo.vbs"
' PARAM: "%L"
' START:
' ICON: C:\Windows\System32\WScript.exe,2
' TOOLTIP: ForEachSelFileDo VBS
'
'
' %L will create an temporary file like "C:\Users\myusername\AppData\Local\Temp\CMDB034.tmp" which holds the list of the selected files.
Option Explicit
On Error Resume Next
DIM vsTCtempList, vsFullName, vsDrive, vsPath, vsFile, vsBase, vsExte, vsSize, vsVers, vsCreated, vsAccessed, vsModified, oTextStream, oFile
DIM vsParent, vsGrand, vsTopFld, vsTopFld2, vsFilesCount, vsTarget, vsArgument, vsNewFilename, FSO, WSO, vsTimestring
Const FORREADING = 1
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSO = CreateObject("WScript.Shell")
vsTCtempList = Wscript.arguments.Item(0) ' The TC temp file due to the "%L" parameter
If FSO.FileExists(vsTCtempList) Then
'//Just for DEBUGging:
'MsgBox "Tempfile is: " & vsTCtempList
'WSO.run "notepad " & vsTCtempList
'//START, loop over all selected files:
Set oTextStream = FSO.OpenTextFile(vsTCtempList,FORREADING)
Do Until oTextStream.AtEndOfStream
vsFullName = oTextStream.ReadLine
Set oFile = FSO.GetFile(vsFullName)
vsFile = FSO.GetFileName(oFile)
vsBase = FSO.GetBaseName(oFile)
vsExte = FSO.GetExtensionName(oFile)
vsCreated = oFile.DateCreated
vsAccessed = oFile.DateLastAccessed
vsModified = oFile.DateLastModified '// on a German PC: 9.7.2016 17:05:40
vsModified = Left (vsModified, InStr (vsModified, " ") - 1) '// 9.7.2016
vsTimestring = Right (Left ("0" + vsModified, InStr ("0" + vsModified, ".") - 1), 2) '// 09
vsModified = Mid (vsModified, InStr (vsModified, ".") + 1) '// 7.2016
vsTimestring = vsTimestring + "." + Right (Left ("0" + vsModified, InStr ("0" + vsModified, ".") - 1), 2) '// '09.07
vsModified = Mid (vsModified, InStr (vsModified, ".") + 1) '// 2016
vsTimestring = vsTimestring + "." + Mid (vsModified, 1, 4) '// 09.07.2016
'MsgBox vsTimestring
'//format vsModified to wanted string:
vsTimestring = mid(vsTimestring,9,2) & mid(vsTimestring,4,2) & mid(vsTimestring,1,2)
'vsTimestring is here 160709
'//develop new file name:
'// do not rename twice:
DIM viLen, vsCheck
vsNewFilename = vsFile
viLen = Len(vsTimestring) '6
vsCheck = Right(vsBase, viLen) 'last 6 signs
If (vsCheck <> vsTimestring) Then
vsNewFilename = vsBase & vsTimestring & "." & vsExte
'msgbox vsNewFilename
End If
'// do not rename twice END
'// Do your work here:
If not (FSO.FileExists(vsNewFilename)) Then
'FSO.MoveFile source, destination
'FSO.MoveFile vsFullName, vsNewFilename
FSO.CopyFile vsFullName, vsNewFilename
End If
Loop
oTextStream.Close
Else
MsgBox "Input file vsTCtempList not found. Check button parameter and quoting.",,"TC-Script Error - ForEachSelFileDo"
End If
Function TimestampNow()
DIM N,W,D,T
N = Now
W = WeekdayName( Weekday(N), true)
D = Year(N) & Right("00" & Month(N), 2) & Right("00" & Day(N), 2)
T = Right("00" & Hour(N), 2) & Right("00" & Minute(N), 2) & Second(N)
TimestampNow = D & "_" & W & "_" & T
'//20130620 082202
'//20130620_Do_083851
End Function 'TimestampNow()