Restoring modified timestamps on Dropbox folders

This script loops through selected folders and sets their modified dates to the oldest .opf it finds inside them.

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    var fsu = DOpus.FSUtil;

    cmd.deselect = false; // Prevent automatic deselection

    DOpus.ClearOutput;

    for (var eSel = new Enumerator(tab.selected_dirs); !eSel.atEnd(); eSel.moveNext()) {
        var dirPath = eSel.item().RealPath;
        var lastMod = Infinity;
        var folderEnum = fsu.ReadDir(dirPath, 'r'); // recursive
        while (!folderEnum.complete) {
            var folderItem = folderEnum.Next();
            if (folderItem.is_dir) continue;
            if (folderItem.ext != '.opf') continue;
            if (folderItem.modify < lastMod) lastMod = folderItem.modify;
        }
        if (lastMod < Infinity) {
            var cmdLine = ('SetAttr FILE="' + dirPath + '" META "lastmodifieddate:' + lastMod.Format('D#yyyy-MM-dd T#HH:mm:ss') + '"');
            DOpus.Output(cmdLine);
            cmd.RunCommand(cmdLine);
        }
    }
    DOpus.Output('\n... done.');
}

Set Modified to .opf.dcf (2.1 KB)

1 Like