Author Topic: ** How to use Rules based file coloring (New in MC v3.1 and MC 3.2 ) **  (Read 28094 times)

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
MultiCommander v3.1 contains support for rule based coloring of file items.

However this feature is experimental and there is no user interface for configure the rules, Yet.
(Since it is experimental, Fell free to reply with feedback with ideas, tips and request on how this should work or be improved)

However. You can setup the rule based coloring using Multi-Script.  And the colors is not kept between restarts you can load that script automatic during startup, or button or hotkey or whatever you want,
And since it is script based you can have different color setup and change between then with a command that you call.

To enable Rule bases file coloring you must first enable it in settings
Menu > Configuration > Explorer Panel Settings > Colors (tab)

Before the configuration for the existing Color of file/folder based on file/folder name there is a new options
[.] (Experimental) Rule based coloring of file and folders
  (This settings will disabled the other file/folder coloring)

Configure Colors
All the rule based file coloring is done from 4 Multi-Script functions

FileColoringClear();        = Removes all Rules
FileColoringAddRule(...); = Add a Rule
FileColoringSetColor(...); = Set Color To a rule
FileColoringRefresh(...);   =  Refresh the coloring system with

You can combine multiple rules and if all of the nested rules are true, Only then is the color set.

All the rule are matches from the first to the last inserted rule. If a match is found for a file it will then
stop searching for another rule to match. So if you having trouble getting the correct color it might be because of the order
the rules are setup.

You first create a rule using FileColoringAddRule(...) and it will return a "rule handle" you then use that rule handle to set a color.

Code: [Select]
FileColoringAddRule(<parent rule if any, else 0> , <field> , <match type> , <value> );
When settings a color to a rule, you can specify both a text and background color. However the background color is only shown IF the options
"Use file specified background color" / "Use folder specified background colors" are enabled.
And to use the default background color use an empty string as background color.

eg.
Code: [Select]
FileColoringSetColor(  $rule , "#FF0000" , "" ); // Use the default specified background color.
Example.
Code: [Select]
// First we need to remove all existing rules. DO NOT FORGET TO DO THIS.
FileColoringClear();

// variable to store Rule in
@var $rule = 0;

// Add Rule - if file extension is jpg, bmp, png, or gif
$rule = FileColoringAddRule(0, "Ext" , "Is", "jpg|bmp|png|gif" );
FileColoringSetColor( $rule , "#FF0000" , "#00FF00" );

// Add Rule - if file extension is zip , rar or 7z
$rule = FileColoringAddRule(0, "Ext" , "Is", "zip|rar|7z" );
FileColoringSetColor( $rule , "#FF9954" , "#00FF00" );

// Add Rule - match the namepart using wildcard against *-Invoice-201?-*
$rule = FileColoringAddRule(0, "namepart" , "wildcard", "*-Invoice-201?-*" );
FileColoringSetColor( $rule , "#4455FF" , "#00FF00" );

// Add Rule - match substring from the full filename  will match "MyFile_abcdef.txt" and "myFile.edf"
$rule = FileColoringAddRule(0, "Fullname" , "contains", "edf" );
FileColoringSetColor( $rule , "#44FFFF" , "#00FF00" );

/ Add Rule - if file has readonly attribute set
$rule = FileColoringAddRule(0, "attribute" , "has", "r" );
FileColoringSetColor( $rule , "#FF2277" , "" );

// Add Rule - If file size is more then 10.000.000 bytes
$rule = FileColoringAddRule(0, "Size" , "MoreThen", "10000000" );
FileColoringSetColor( $rule , "#BB9988" , "#00FF00" );

// Add Rule - If date is before 2013-01-01 00:00:00 (Date MUST be ISO formatted.)
$rule = FileColoringAddRule(0, "Date" , "Before", "2013-01-01 00:00:00" );
FileColoringSetColor( $rule , "#444433" , "#00FF00" );

// Add Rule - Combine two rules.
//  if Size is MoreThen 10.000 bytes AND file extension is "txt"
$rule = FileColoringAddRule(0, "Size" , "MoreThen", "10000" );
$rule = FileColoringAddRule($rule, "Ext" , "Is", "txt" );
FileColoringSetColor( $rule , "#FF3299" , "#00FF00" );

// Revalidate all file coloring.
FileColoringRefresh();

Current supported Field

Fullname
Namepart
Ext
Size
Date
Attribute
= More to be added, for example extended file properties provided by extension. (Like they are used by MultiRename )


Match Type

Is        - If a string or numeric values matches exactly (String match is not case sensitive) (Fullname,namepart,ext,size)
Wildcard  - If a wildcard value matches (Fullname,namepart,ext)
RegExp    - If regular expression matches ( Fullname,namepart,ext) (Not Implemented yet)
Contains  - If a substring exists  (Fullname,namepart,ext)
Beginwith - If a string begin with...
Endswith  - if a string ends with...
LessThan  - If a numeric value is less then specified value (Like size)
MoreThan  - If a numeric value is more then specified value (Like size)
Before    - If a date value is before specified value
After     - If a date value is after specified value
Has       - If any of the specified flags are set. (used for attribute, "arshdl" flags are supported )
HasNot  - If any of the specified flags are NOT set (From Build 1412+)

= More matching type will be added

Attributes
When matching attribute you will use Has or HasNot as matchtype and as value you specify what attributes you want to check
and if any if them is found then the rule is true.

a - Archive flag
r - Readonly
s - System
h - Hidden
d - Directory / folder
l - Reparse point
c - compressed
e - encrypted
o - offline
1 - shortcut (lnk)
2 - shortcut (lnk) to folder
3 - symlink
4 - junction
5 - mount point
6 - network server
7 - network share

Example
Code: [Select]
// Has Readonly attribute
$rule = FileColoringAddRule(0, "Attribute" , "Has", "r" );

// Has System or Hidden attribute
$rule = FileColoringAddRule(0, "Attribute" , "Has", "sh" );

// DO NOT have archive attribute
$rule = FileColoringAddRule(0, "Attribute" , "HasNot", "a" );

Date Range (From build 1412+)
If you set field to "date" and use any Match Type of the following Is, LessThan or MoreThan then you can add rule like

Using LessThan/MoreThan you can specify X number of hours / days / weeks / months old.
for match value use number first then add h for Hour , d for day, w for weeks and m for months
Example
Code: [Select]
// More than 2 days old
$rule = FileColoringAddRule(0, "Date" , "MoreThan", "2d" );

// More than 48 hours old
$rule = FileColoringAddRule(0, "Date" , "MoreThan", "48h" );

// Less than 2 week
$rule = FileColoringAddRule(0, "Date" , "LessThan", "2w" );
Be aware. "2d" and "48h" are NOT the same.  Day matching will match days from current day. not current hour. so "1d" is current day only.

Using  "Is"  as Match Type you can specify Today, Yesterday, ThisWeek, ThisMonth, ThisYear.
Code: [Select]
// Rule for today
$rule = FileColoringAddRule(0, "Date" , "Is", "Today" );
// Yesterday.
$rule = FileColoringAddRule(0, "Date" , "Is", "Yesterday" );
// Current week. (will use regional settings in computer to figure out if first day of week is sunday or monday )
$rule = FileColoringAddRule(0, "Date" , "Is", "ThisWeek" );
// Current month
$rule = FileColoringAddRule(0, "Date" , "Is", "ThisMonth" );
// Current year
$rule = FileColoringAddRule(0, "Date" , "Is", "ThisYear" );


Updated 2013-05-24 - MC 3.1.1 Beta b1412,
   Added info about date additions in It now allows date rules for x days old, x weeks old or rule for today, thisweek and so on.
   MatchType HasNot to be used for attributes rules added.
   more file attributes not supported

   
« Last Edit: June 17, 2013, 15:16:02 by Mathias (Author) »

Jungle

  • Contributor
  • VIP Member
  • *****
  • Posts: 538
  • Old Skull
    • View Profile
Re: How to use Rules based file coloring (New in MC v3.1)
« Reply #1 on: April 30, 2013, 11:41:47 »
LessThen should be LessThan
MoreThen should be MoreThan

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Re: ** How to use Rules based file coloring (New in MC v3.1) **
« Reply #2 on: April 30, 2013, 11:56:53 »
Yes it should.. Damn.. I double checked that.

Well. I Will fix that for the next version.
(But I might have a UI for it then)

« Last Edit: April 30, 2013, 12:01:27 by Mathias (Author) »

ice-man

  • Active Member
  • ***
  • Posts: 56
  • The Little Extra
    • View Profile
Re: ** How to use Rules based file coloring (New in MC v3.1) **
« Reply #3 on: May 02, 2013, 11:23:43 »
How about a way to set color if a date is less or more then x days.
Then you can show files that are from today in a different color
Intel i7-6700K - Running on latest Windows 10 64bit Insider Preview

Jungle

  • Contributor
  • VIP Member
  • *****
  • Posts: 538
  • Old Skull
    • View Profile
Re: ** How to use Rules based file coloring (New in MC v3.1) **
« Reply #4 on: May 02, 2013, 13:07:04 »
How about a way to set color if a date is less or more then x days.
Then you can show files that are from today in a different color
It is possible.

Code: [Select]
// First we need to remove all existing rules. DO NOT FORGET TO DO THIS.
FileColoringClear();

// variable to store Rule in
@var $rule = 0;

// Add Rule - If date is within 10 days from now
@var $now = GetTime();
@var $then = $now - 60*60*24*10;
@var $now_str = FormatDate( "yyyy-MM-dd " , $now ) + FormatTime("HH:mm:ss", $now);
@var $then_str = FormatDate( "yyyy-MM-dd 00:00:00" , $then );

$rule = FileColoringAddRule(0, "Date" , "Before", $now_str );
$rule = FileColoringAddRule($rule, "Date" , "After", $then_str );
FileColoringSetColor( $rule , "#444433" , "#00FF00" );

// Revalidate all file coloring.
FileColoringRefresh();

But there are 2 moments.
1. GetTime() always returns uncorrected time. E.g. if i have GMT+04, at 15:00 GetTime() will return 11:00
2. Last modified datetime is used when checking files.
« Last Edit: May 02, 2013, 13:08:46 by Jungle »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Re: ** How to use Rules based file coloring (New in MC v3.1) **
« Reply #5 on: May 02, 2013, 13:26:16 »
How about a way to set color if a date is less or more then x days.
Then you can show files that are from today in a different color
It is possible.

Code: [Select]
// First we need to remove all existing rules. DO NOT FORGET TO DO THIS.
FileColoringClear();

// variable to store Rule in
@var $rule = 0;

// Add Rule - If date is within 10 days from now
@var $now = GetTime();
@var $then = $now - 60*60*24*10;
@var $now_str = FormatDate( "yyyy-MM-dd " , $now ) + FormatTime("HH:mm:ss", $now);
@var $then_str = FormatDate( "yyyy-MM-dd 00:00:00" , $then );

$rule = FileColoringAddRule(0, "Date" , "Before", $now_str );
$rule = FileColoringAddRule($rule, "Date" , "After", $then_str );
FileColoringSetColor( $rule , "#444433" , "#00FF00" );

// Revalidate all file coloring.
FileColoringRefresh();

But there are 2 moments.
1. GetTime() always returns uncorrected time. E.g. if i have GMT+04, at 15:00 GetTime() will return 11:00
2. Last modified datetime is used when checking files.

Well Yes, you can do it with script. But configuring using script is only a workaround for now UNTIL the UI has been added.
(Will probably keep the ability to configure using script. Because it make it more powerful and you can switch to new color setups fast.
But it should not be require to do scripting to configure the rules in the future. )

Btw  "GetTime(1);" will return UTC time..  and there is also "TimeLocal2UTC(..)" that convert Local > UTC time. and TimeUTC2Local that convert the other way

But someway to set a rule for Today, or if a file is 2 days old or older then 5 weeks might be useful.

Maybe something like.

FileColoringAddRule(0, "Date" , "Is", "today"); // from today.
FileColoringAddRule(0, "Date" , "Is", "thisweek"); // if file is from current week
FileColoringAddRule(0, "Date" , "LessThan", "5d"); // Less than 5 days old
FileColoringAddRule(0, "Date" , "MoreThan", "5w"); // more than 5 weeks old

« Last Edit: May 02, 2013, 13:32:33 by Mathias (Author) »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
MC 3.1.1 Beta (Build 1412)
Date and Attributes rule support have been enhanced.

Date now support ranges like Is Today , Is ThisWeek , LessThan 2d old, LessThan 1h hour, MoreThan 2w old
(LessThan 2d old and LessThan 48h old is NOT the same.
day matches do whole days starting with today. so LessThan 1d old is the same as current day only. )

Attributes can not be match using HasNot and also more attributes are supported.

The first post is updated with information on how to use the new date and attribute rules.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
MC 3.1.1 Beta (Build 1420)
Load and Save rule from script has been added

Code: [Select]
FileColoringLoad( <filename> );
FileColoringSave( <filename> );

Also FileColoringAddCustomColor and FileColoringSetCustomColor are added.
With them you can set a specific color to a file/files that does not use the normal rules.
Code: [Select]
@var $id = FileColoringAddCustomColor( <TextColor> , <Background Color> );

FileColoringSetCustomColor( $id , "D:\MyFile.txt" );
FileColoringSetCustomColor( $id , "D:\MyFolder\Img*.jpg", true ); // set third parameter to 'true' do to wildcard matching
There is one glitch with the custom file color. It only works if the file have been shown and are in the UI cache. So it might not be so useful.
I might remove this functions in the future. Normal rules can often be used instead.

The idea with this functions was to be able to color just the selected files. for example, Select some file set them to color 1, then select some other files set them to color2 and so on.  But I think file tagging will solve that need when that is finished and that will work better.