Command: ClipAttr (copy/paste timestamps between files)

Share script buttons and script add-ins to extend and modify Opus.
User avatar
Posts: 36498
Joined: 07 Nov 2004, 01:30
OS: Windows 10 64-bit
Opus: Directory Opus 12
Location: London, UK
  • Overview:

    This script adds a ClipAttr command.

    • ClipAttr COPY will copy the Created and Modified timestamps from all selected folders & files into a variable (which acts like the clipboard, but does not modify your actual clipboard).

    • ClipAttr PASTE will set the Created and Modified timestamps on all selected folders & files to match the values copied earlier.

    • If you don't have the same number of items selected when you copy and when you paste, the list of timestamps will loop around (if needed).

      In particular, if you use ClipAttr COPY on a single item, and then select lots of items and use ClipAttr PASTE, you can paste one item's timestamps over lots of other items.

      You will usually either copy just one timestamp to apply to however many items, or copy and paste between the same number of items, but you don't have to.

    • More actions may be added in the future.

  • Installation:

    • Download Clipboard_Attributes.vbs.txt and drag it to Preferences / Toolbars / Scripts.

      (2.72 KiB) Downloaded 115 times

    • With the script installed, you can create toolbar buttons or hotkeys which use the ClipAttr command, as described in the overview section above.

    • Here are two pre-made buttons you can drag to a toolbar:

      Copy Dates.dcf
      (252 Bytes) Downloaded 101 times

      Paste Dates.dcf
      (250 Bytes) Downloaded 92 times

  • History:

    • 1.0 (18/May/2015): Initial version.

  • Limitations:

    • The stored timestamps do not persist if you exit and restart Opus. This may be added in the future.
    • Timestamp precision is only up to 1 second. Exact millisecond timestamps are not set at present.

  • Script code:

    The script code from the download above is reproduced below. This is for people browsing the forum for scripting techniques. You do not need to care about this code if you just want to use the script.

    Code: Select all

    option explicit

    ' Clipboard Attributes
    ' (C) 2015 Leo Davidson
    ' This is a script for Directory Opus.
    ' See for development information.

    ' Called by Directory Opus to initialize the script
    Function OnInit(initData) = "Clipboard Attributes"
       initData.desc = "Copy and paste file timestamps"
       initData.copyright = "(C) 2015 Leo Davidson"
       initData.version = "1.0"
       initData.default_enable = true

       Dim cmd

       Set cmd = initData.AddCommand = "ClipAttr"
       cmd.method = "OnClipAttr"
       cmd.desc = ""
       cmd.label = "ClipAttr"
       cmd.template = "COPY/S,PASTE/S"
    End Function

    ' Implement the ClipAttr command
    Function OnClipAttr(scriptCmdData)
       If (scriptCmdData.Func.args.got_arg.COPY) Then
       ElseIf (scriptCmdData.Func.args.got_arg.PASTE) Then
       End If
    End Function

    Function ZeroPad(s,c)
       ZeroPad = s
       Do While (Len(ZeroPad) < c)
          ZeroPad = "0" & ZeroPad
    End Function

    Function DateTimeForCmd(d)
       DateTimeForCmd = ZeroPad(d.year,4) & "-" & ZeroPad(d.month,2) & "-" & ZeroPad(,2) & " " _
          & ZeroPad(d.hour,2) & ":" & ZeroPad(d.min,2) & ":" & ZeroPad(d.sec,2)
    End Function

    Function OnClipAttrCopy(scriptCmdData)

       scriptCmdData.func.command.deselect = False

       Dim vecModified, vecCreated, fileItem
       Set vecModified = DOpus.Create.Vector
       Set vecCreated = DOpus.Create.Vector
       For Each fileItem in scriptCmdData.func.sourcetab.selected
          vecModified.push_back( fileItem.modify )
          vecCreated.push_back( fileitem.create )

       Dim varMod, varCre
       Set varMod = Script.vars("vecModified")
       Set varCre = Script.vars("vecCreated")
       varMod.value = vecModified
    '   varMod.persist = True
       varCre.value = vecCreated
    '   varCre.persist = True

    End Function

    Function OnClipAttrPaste(scriptCmdData)

       Dim cmd, cmdLine
       Set cmd = scriptCmdData.func.command

       cmd.deselect = False

       If (Not (Script.vars.Exists("vecModified") And Script.vars.Exists("vecCreated"))) Then
          Exit Function
       End If

       Dim vecModified, vecCreated, mi, mt, ci, ct, fileItem
       Set vecModified = Script.vars.Get("vecModified")
       Set vecCreated = Script.vars.Get("vecCreated")
       mi = 0
       ci = 0
       mt = vecModified.count
       ct = vecCreated.count
       If (mt = 0 Or ct = 0) Then
          Exit Function
       End If
       For Each fileItem in scriptCmdData.func.sourcetab.selected
          cmdLine = "SetAttr MODIFIED=""" & DateTimeForCmd(vecModified(mi)) _
             & """ CREATED=""" & DateTimeForCmd(vecCreated(ci)) & """"

          cmd.AddFile fileItem

          mi = mi + 1
          ci = ci + 1
          If (mi >= mt) Then mi = 0
          If (ci >= ct) Then ci = 0

    End Function

Registered Opus Pro User
Posts: 7
Joined: 02 Sep 2006, 13:03
OS: Windows 10 64-bit
Opus: Directory Opus 11
Location: Hayward, CA
I also use it on my "All files and folders" Windows file type to create a context menu item.

User avatar
Registered Opus Pro User
Posts: 54
Joined: 03 Nov 2006, 09:21
OS: Windows 7 32-bit
Opus: Directory Opus 11
Location: Saint Paul, MN
Thanks so much. I'd been trying to figure this out, without a lot of success. Your script and buttons were great!!!

Return to “Script Buttons & Add-Ins”