Copy timestamp based on oldest modified date within selection

The reason behind it is a long, uninteresting, story.
I needed to split large PDF files into smaller ones. For instance FileXYZ.pdf (500MB) into 10 parts, like FileXYZ-part1.pdf .. part2.pdf etc.
Obviously the modified timestamp of these part1, part2 files are the same as the created timestamp.

Right now I use
"ClipboardEx COPYTIMESTAMPS" and
"ClipboardEx PASTETIMESTAMPS=modified"
to copy the timestamp of the 'old' file onto the new ones.

This is fine for a limited number of files, but I've to do some 250 files.

I wonder if it would be possible to:
select the old, large pdf
and the new files
and change the modified date of the new ones, based on the oldest modified date within the selection.

It would faster, less clicks especially when assigning a hotkey combination to this action.

SnagIt-07092020 093433

Here's a button which should do that.

Test it in a new folder on some dummy files first to make sure it works how you want it to.

Modified to Oldest.dcf (4.6 KB)

Script code for reference:

function OnClick(clickData)
    var cmd = clickData.func.command;
    cmd.deselect = false;

	// Change to .selected to do files and folders (untested), not just files (tested).
	var selected = clickData.func.sourcetab.selected_files;

	var oldestItem = null;

    for (var files = new Enumerator(selected); !files.atEnd(); files.moveNext())
        var item = files.item();

		if (oldestItem == null || oldestItem.modify.Compare(item.modify) > 0)
			oldestItem = item;

	if (oldestItem == null)

	var anyFiles = false;

    for (var files = new Enumerator(selected); !files.atEnd(); files.moveNext())
        var item = files.item();

		if (oldestItem != item)
			anyFiles = true;

	if (!anyFiles)

	var timeStr = DateTimeForCmd(oldestItem.modify);
	var cmdLine = 'SetAttr MODIFIED="' + timeStr + '"';

function ZeroPad(s,c)
	s = s + "";
	while(s.length < c)
		s = "0" + s;
	return s;

function DateTimeForCmd(d)
	var year, month, day, hour, minute, second;

	if (DOpus.TypeOf(d) == "object.Date")
		// Opus date object
		year   = d.year;
		month  = d.month;
		day    =;
		hour   = d.hour;
		minute = d.min;
		second = d.sec;
		// Javascript date object
		year   = d.getFullYear();
		month  = d.getMonth() + 1;
		day    = d.getDate();
		hour   = d.getHours();
		minute = d.getMinutes();
		second = d.getSeconds();

	year   = ZeroPad(year,   4);
	month  = ZeroPad(month,  2);
	day    = ZeroPad(day,    2);
	hour   = ZeroPad(hour,   2);
	minute = ZeroPad(minute, 2);
	second = ZeroPad(second, 2);

	return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
1 Like

THANK you very much indeed!
This is really magnificent.
It saves a lot of boring clicks -and- time.
I knew it was a strange request, a 'long shot', so to say and I honestly didn't expect a solution.

Many thanks again.

1 Like

Please allow me to get back on this old thread. I use the above quite regularly: stored it under a Function key. I wonder, would it be possible to 'expand' the script so it will use a folder date as oldest source.

It works fine on files, but not when using folder file combination.

Drop it, when it is too complex. Just asking.


See the comment at the top of the script.