Select most recently modified file in the current directory?

I've often wished that I can press a shortcut to select the most recently modified file in the current directory.

This would particurlarly useful if you navigate to your download folder (containing many files) and you just have to press a single shortcut to navigate and select the file you downloaded a few seconds ago.

Since the select command doesn't provide an appropriate argument I'm wondering if there is any other solution to achieve that?

BTW, my workaround I have used so far looks like that:

Set SORTORDER=Files
Set SORTBY=modified 
Select FIRST 
Set SORTORDER=Folders
Set SORTBY=name 

But it feels really inconvenient because everything is re-layouted multiple times and it doesn't keep the original sort state, instead after performing this command the file display is always in name/folders mode (which obviously may not be your initial configuration). Thus I would really be happy to have a dedicated command (or argument) for this ...

Here is a little improvement to make the behaviour more stable against reversed sort direction:

Set SORTORDER=Files
Set SORTBY=modified 
Set SORTREVERSE=Off
Select FIRST 
Set SORTORDER=Folders
Set SORTBY=name 

Such a native command should support multiple arguments for selection like select RECENT=filesfirst,created,modified. This means select the file (if no files than folder) that was recently created or modified whatever was later.

+1

I like that idea very much.

I still have the problem, that I can not create a single script that take the created as well as the modified time into account. This means I want to select the most recently modified or created file (whatever was later). This is particurlarly needed to catch files coming from extracted archives (which often restores the modification time). After extracting an archive my script mostly fails.

The main idea behind my script (that is given above) can't take both times into account. That was the reason why I asked for a new command.

Now I'm wondering if it is possible to write a small VBScript for this puprpose or are VBScripts only applicable for renaming?

Leo, do you have any nice idea how to select the most recent file in the current directory considering the modified and the creation time (whatever was later)?

No.

I have read the JScript documentation and was able to write a small script that finds out the most recently modified or created file.

Unfortunately I'm not sure how I can use this script in a command!?

To be more precise I'm wondering if I can embed my script directly into a DOpus command (e.g. using the @script modifier)!? I don't want to have the script flying around in my filesystem, instead I want to keep things together (e.g. the script should work in the exported portable version as well). Thus how can I configure a single command that executes my script code (given below) without the need to save the script into an actual file!?

var args = WScript.arguments;
if (args.length > 0) {
    var ws = WScript.CreateObject("WScript.Shell");
    var fs = new ActiveXObject('Scripting.FileSystemObject');
    var folder = fs.GetFolder(args(0));
    var youngestFile, youngestFileDate;
    for (files = new Enumerator(folder.files); !files.atEnd(); files.moveNext()) {
        var file = files.item();
        var fileDate = Math.max(file.DateCreated, file.DateLastModified);
        if (fs.FileExists(file) && youngestFile == null || fileDate > youngestFileDate) {
            youngestFile = file;
            youngestFileDate = fileDate;
        }
    }
    if (youngestFile != null) {
        ws.Run("dopusrt /acmd Select " + youngestFile + " DESELECTNOMATCH MAKEVISIBLE");
    }
} else {
    WScript.Echo("argument missing");
}

@script is only for rename scripts, but you can still take advantage of it, like this:

+1 for this request.

The next update will have new Select DATE and Select SIZE commands which can do this, and a few other things.

Glad to hear that. :thumbsup:

Will the Select DATE command consider the modified and the creation time (whatever was later)?

Sweet. Thanks for the update, Leo.