Filter locked files (in access)

How would I create a filter that would dynamically match only those files that are locked and can't be changed/written to (for example, files that are open in another process)?

In TC I'm using this plugin http://en.totalcmd.pl/download/wdx/fls/UnicodeLockedTest to check whether a file is locked or not. Is there something similar for Opus? Please note that I'm not looking for a way to test "read-only" attributes, but files that are actually in use by another process.

I'd like to highlight all locked files in red — that's rather useful when you want to rename a file and realize it's locked only after you've entered the new name.
Thank you

A script could probably add a column that would indicate this state (by attempting to open the file for writing), and then you could filter on the column. There'd be no way of making it update in real time (not reliably anyway) though.

Thanks for a prompt response.
Such script would work — after all, I could make it run on refresh as well, right? That would suffice (the other addon I mentioned also requires a refresh of the current lister, so not real-time either). Would you kindly help with this script?
Also, if I understand correctly, I could then use this script column as input to a filter, right? And if so, would I be able to hide the column or would it need to be displayed for the filter to work?

Yes the filter would test the value of the column. It wouldn't need to be visible to do that.

I can help write it although I'm on holiday at the moment. If no one else steps in to do it bump this thread in about 10 days and I'll take a look!

Thank you and enjoy your holidays!

Please also link your account if you want us to write scripts for you and answer lots of detailed questions. :slight_smile:

I have just started using Opus, so still only a few days into my trial. Just coming from Total Commander, another file manager with extensive configuration, trying to set up Opus the same way I've set TC to see if it makes sense to switch to Opus as my primary file manager. That explains a bunch of questions from me :slight_smile:
Is there a way to link a trial account?

No you can't link trial accounts, but hopefully you'll stick around past the end of your trial :slight_smile:

Oh, that is fair enough then. :slight_smile: Your questions were so in-depth I assumed you had been using Opus for a long time.

I'll see if I can write the script later today, depending on how much time I have to spent with cats and vets.

@questions were so in-depth
I guess the side effect of having spent much time configuring TC

@hopefully you'll stick
Me too, hopefully I'll be able to set everything I need as I do like the app so far and the interface is better (and wonder how I've missed it before)

Here's a basic script which implements the column. It will show:

[ul][li]"Writable" if it is able to open a file for writing.[/li]
[li]"Read-Only" if it can't open it for writing but can open it for reading.[/li]
[li]"Inaccessible" otherwise. (And nothing at all for folders.)[/li][/ul]
(It doesn't check for the rare case that something can be written but not read. That will just be reported as "Writable" the same as a normal read/write file.)

Important: You may want to wait until Opus 12.0.5 beta is out before using this, assuming you have UAC enabled. In current Opus versions, the column can/will trigger annoying UAC prompts if it cannot access things. I just made a code-change for 12.0.5 which allows scripts to request that UAC elevation does not happen, and the script uses that, but versions before 12.0.5 will ignore the request.

Also important: The script opens files for writing and then closes them. In my testing so far, this has not modified any of the files, but since the script is brand new and has only been tested a limited amount on my own machine, I advise using it first on some test files you don't care about, just in case. I don't think there is any risk, but it's better safe than sorry.

Download and drop into Preferences / Toolbars / Scripts:
Locked_Column.js.txt (1.54 KB)

You'll then have a Scripts > Locked column which can be added to the file display.

Code for reference (same as the .txt file):

[code]// Locked Column
// (c) 2016 Leo Davidson

// This is a script for Directory Opus.
// See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.

var strWritable = "Writable";
var strReadOnly = "Read-Only";
var strInaccessible = "Inaccessible";

// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "Locked Column";
initData.desc = "A column which shows which files can be modified.";
initData.copyright = "(c) 2016 Leo Davidson";
initData.version = "1.0";
initData.default_enable = true;
// initData.min_version = "12.0.5"; // Will work better with Opus 12.0.5 once it is released. Required to prevent UAC prompts.

var col = initData.AddColumn();
col.name = "Locked";
col.method = "OnLocked";
col.label = "Locked";
col.justify = "left";
col.autogroup = true;
col.match.push_back(strWritable);	// when searching, these are the options.
col.match.push_back(strReadOnly);
col.match.push_back(strInaccessible);

}

// Implement the Locked column
function OnLocked(scriptColData)
{
if (scriptColData.item.is_dir)
{
return;
}

var file = scriptColData.item.Open("we","ElevateNoAsk");
var openError = file.error;
file.Close();
if (openError == 0)
{
	scriptColData.value = strWritable;
	return;
}

file = scriptColData.item.Open("","ElevateNoAsk");
openError = file.error;
file.Close();
if (openError == 0)
{
	scriptColData.value = strReadOnly;
	return;
}

scriptColData.value = strInaccessible;

}[/code]

Thanks a lot for the script! I've checked and it works for inaccessible files without UAC prompts, but read-only files do show prompts all the time. Will check it out in more details with the next update.

Would you kindly suggest a quick and reliable way to test for any potential issues (I also don't expect anything from opening and closing a file, but just to be on the safe side)?
I was thinking of the following routine:

  1. Copy a folder somewhere
  2. Turn the column on
  3. Refresh/reenter this folder (watch out the parent has no files not to touch them by accident)
    Question: would this script update on "Go REFRESH=source" or would I need to exit and re-enter the folder?
  4. Launch an app that is using files in this folder (ideally get an app that just loads dlls to make them locked, but still unchanged to ease further comparison)
  5. See if locked files are specified as inaccessible
  6. Use Opus sync function with "byte comparison" to see if the script has introduced any changes.

For read-only test I'm not sure I understand this — is there a difference between read-only file attribute and read-only check in your script? I mean, can a file be a) accessible, b) NOT have read-only attribute, but be c) non-writeable?

When something opens a file it can specify whether other things should also be able to open the file for reading and/or writing. So a file may be read-only due to that. File permissions can also do the same thing, without anything having to have the file open.

The script will run whenever the column is refreshed, which does indeed include in reaction to the Go REFRESH command (and variants).

Your test steps look good to me.