GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Automatically move last downloaded file

Say I have folder "Pics" open in the lister and recently downloaded a file "01.jpg" into my "Download" folder. Is there a way for me make a button that will to automatically move the last file added to the "Download" folder into the "Pics" folder? (or into whatever folder is currently open in the lister?)

This will do that, based on the files' modified timestamps.

(If that doesn't work, using the created timestamps might work better, depending on what's making the downloaded files and how it's managing the two timestamps.)

It uses the system Downloads folder (/downloads alias in Opus) but you can change that near the top if needed.

Script for reference:

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

	var newest = null;
	var folderEnum = DOpus.FSUtil.ReadDir("/downloads", false);

	while (!folderEnum.complete)
	{
		var item = folderEnum.next;
		if (!item.is_dir && item.name != "desktop.ini")
		{
			if (newest == null || newest.modify.Compare(item.modify) < 0)
			{
				newest = item;
			}
		}
	}

	if (newest != null)
	{
		// "Copy HERE" doesn't work with scripting; use SetDestTab instead.
		cmd.SetDestTab(cmd.sourcetab);
		cmd.RunCommand('Copy MOVE FILE="' + newest + '"');
	}
}

Works great - thanks!

1 Like

Is there a way to modify this script so it only moves the most recently modified file if it was modified within the last 10 minutes? This would help me avoid moving files accidentally.

Replace

if (newest != null)

with

if (newest != null && DOpus.Create.Date() - newest.modify < 10 * 60 * 1000)
2 Likes

how about when a certain file type was created, so say only with .jpg files, never mind the date they where created