GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Restoring modified timestamps on Dropbox folders

I have just synced a lot of folders from Dropbox in anticipation of finally going through everything and organizing them For years, they have just been in the cloud with duplicates and no real organization. I noticed that all the folder modified times (fortunately not the files inside them) have all been changed to the download date. I have a lot of directories with three deep level child folders. Now all those folders have bad modified dates. Is there some way of changing the folder attributes to the oldest child file within them?

Folder dates are inherently fragile, and trying to keep them to any particular date can end up being futile. If any file or folder directly below the folder is added, deleted or renamed then the folder's modified date will be bumped to the current time. So even if you did set the dates how you want them, as soon as you start doing things inside the folders the dates will be changed again.

A better approach might be to use a column which shows the timestamp of the newest file below each folder:

If you want the oldest file rather than the newest, that would be an easy change to make to the script. (Let me know if you need that. It should only take a few minutes.) But usually people are looking for the newest file (i.e. the most recently changed file), so I wonder if you meant that instead? (I get the two confused sometimes myself, as file dates are kind of the opposite way around to file sizes.)

Is there a way of doing a flat view of the directory and then applying the datetime attributes based on the newest file? The .opf files in the child folders indicate the last time I worked on the library.

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


    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('\n... done.');

Set Modified to .opf.dcf (2.1 KB)

1 Like