Is it possible for TC to calculate the difference between the "Date Created" and "Date Modified" of file?
I would like to do this for several files and list the difference for each file.
Any help is appreciated.
How calculate days between DateCreated & DateModified ?
Moderators: white, Hacker, petermad, Stefan2
VBScript: ForEachSelFileDo-TimeDiff.VBS
For example with a script, like this VBScript:
Set oItem = FSO.GetFile(aLineArray(i))
sCreated = oItem.DateCreated
sModified = oItem.DateLastModified
iTimeDiff = Datediff("s",sCreated,sModified)
MsgBox sName & vbLF & "Create / Modify diff: " & round(iTimeDiff / 60,2) & " minutes."
Example VBS script:
ForEachSelFileDo-TimeDiff.VBS
- - -
You can also use DateDiff with 'd'ay option:
MsgBox sName & vbLF & "Create / Modify diff: " & Datediff("d",sCreated,sModified) & " days."
That is less accurate in some circumstances like some-hour-only differences.
More information e.g. at http://ss64.com/vb/datediff.html
Set oItem = FSO.GetFile(aLineArray(i))
sCreated = oItem.DateCreated
sModified = oItem.DateLastModified
iTimeDiff = Datediff("s",sCreated,sModified)
MsgBox sName & vbLF & "Create / Modify diff: " & round(iTimeDiff / 60,2) & " minutes."
---------------------------
---------------------------
ForEachSelFileDo-TimeDiff.VBS
Create / Modify diff: 11,8 minutes.
---------------------------
OK
---------------------------
Example VBS script:
ForEachSelFileDo-TimeDiff.VBS
Code: Select all
'// ===========================================================
'// VBScript for Total Commander, by Stefan
'// ForEachSelFileDo-TimeDiff.VBS, Version 16.1230
'// Forum: http://ghisler.ch/board/viewtopic.php?t=47019
'//
'// More examples: http://ghisler.ch/board/viewtopic.php?p=305571#305571
'// My FAQs: http://ghisler.ch/board/viewtopic.php?p=287481#287481
'//
'// Purpose: Calculate the difference between two timestamps
'// Example: See below
'//
'// TC Button:
'// CMD: "D:\rive\path\to this\MyScript.vbs"
'// PARAM: "%L"
'//
'// Hint:
'// TCs parameter "%L" (use quotes) provides path to temp file with all selected file names.
'// (right click an button, chose "Change...", press F1 key and read the help for more)
'//
'// Prepare: Scroll down to "UserWorkHere" and add your code. <<< U S E R S E T T I N G S.
'// USAGE: Select your files, execute this script... done.
'// ===========================================================
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
If (Wscript.arguments.count < 1) Then
MsgBox "Please use from TC with parameter like '%L'",,"VBScript - ERROR"
WScript.Quit
Else
sTCtempList = Wscript.arguments.Item(0) ' The TC temp file due the "%L"
End If
If FSO.FileExists(sTCtempList) Then
Set oTextStream = FSO.OpenTextFile(sTCtempList,ForReading)
sFileContent = oTextStream.ReadAll
oTextStream.Close
aLineArray = split(sFileContent,vbCRLF)
'// =================== For each line in TCs temp list, Do your work:
For i=0 To UBound(aLineArray) -1
Set oItem = FSO.GetFile(aLineArray(i)) '//Ex: "X:\Work\Orders\File.txt"
sPath = oItem.ParentFolder '//Ex: "X:\Work\Orders"
sPath = sPath & "\" '//Ex: "X:\Work\Orders\"
sName = FSO.GetFileName(oItem) '//Ex: "File.txt"
sBase = FSO.GetBaseName(oItem) '//Ex: "File"
sExte = FSO.GetExtensionName(oItem) '//Ex: "txt"
sSize = oItem.Size
sVers = FSO.GetFileVersion(oItem)
sCreated = oItem.DateCreated
sAccessed = oItem.DateLastAccessed
sModified = oItem.DateLastModified
Set oItem = Nothing
'// ################################################################## UserWorkHere:
'// DO YOUR WORK HERE (For each line in TCs temp list):
'EXAMPLE: sNewName = Replace(sName, "a","X")
'EXAMPLE: MsgBox sPath & sName & vbLF & sPath & sNewName
'EXAMPLE: If NOT (FSO.FileExists(sPath & sNewName)) Then
'EXAMPLE: '//Command disabled by comment sign ' :
'EXAMPLE: 'FSO.MoveFile sPath & sName, sPath & sNewName
'EXAMPLE: Else
'EXAMPLE: End If
iTimeDiff = Datediff("s",sCreated,sModified)
'MsgBox sName & vbLF & "Create / Modify diff: " & round(iTimeDiff / 60,2) & " minutes."
'//The question was about diff in days:
MsgBox sName & vbLF & "Created: " & sCreated & vbLF & "Modifed: " & sModified & vbLF & "Create / Modify diff: " & round(iTimeDiff / 60 / 60 / 24,2) & " days."
'// Ex: ---------------------------
'// Ex:
'// Ex: ---------------------------
'// Ex: Datei.jpg
'// Ex: Created: 28.10.2016 20:58:53
'// Ex: Modifed: 11.12.2016 12:03:29
'// Ex: Create / Modify diff: 43,63 days.
'// Ex: ---------------------------
'// Ex: OK
'// Ex: ---------------------------
'// Ex: ---------------------------
'// Ex:
'// Ex: ---------------------------
'// Ex: vbs.vbs
'// Ex: Created: 28.10.2016 21:00:49
'// Ex: Modifed: 28.10.2016 22:44:58
'// Ex: Create / Modify diff: 0,07 days.
'// Ex: ---------------------------
'// Ex: OK
'// Ex: ---------------------------
'// Ex: ---------------------------
'// Ex:
'// Ex: ---------------------------
'// Ex: PureBasic.pdf
'// Ex: Created: 16.08.2014 13:11:35
'// Ex: Modifed: 30.05.2014 17:00:30
'// Ex: Create / Modify diff: -77,84 days.
'// Ex: ---------------------------
'// Ex: OK
'// Ex: ---------------------------
'// DO YOUR WORK ABOVE.
'// ##################################################################
Next
Else
MsgBox "Input file 'sTCtempList' (%L) not found OR no selection done before.",,"TCs-VBScript - ERROR"
WScript.Quit
End If
- - -
You can also use DateDiff with 'd'ay option:
MsgBox sName & vbLF & "Create / Modify diff: " & Datediff("d",sCreated,sModified) & " days."
That is less accurate in some circumstances like some-hour-only differences.
More information e.g. at http://ss64.com/vb/datediff.html