Define colors by file type - only if ...

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
kodepr
Junior Member
Junior Member
Posts: 45
Joined: 2019-09-05, 08:13 UTC

Define colors by file type - only if ...

Post by *kodepr »

Hello,

For *.rvt, *.rte, *.rfa and *.rft extensions the native software creates backups with an automatic numbering suffix (.nnnn), by default in the same folder as the original file:

Filename.rvt
Filename.0001.rvt
Filename.0002.rvt
etc

Is it possible to define different colors by file type:
  • one for the oringal files (Filename.rvt)
  • and a different one for the backup files (Filename.0001.rvt, Filename.0002.rvt, ...) but ONLY if they are in the same folder as the original file (Filename.rvt) to avoid applying the "backup" color to a non-backup file that just happens to end with 4 numbers preceded by a dot?
Result should be as follows, where ABC.0245.rvt is in the "original" color because it is not a backup file since there is no ABC.rvt file in the same folder:

Filename.rvt
Filename.0001.rvt
Filename.0002.rvt

ABC.0245.rvt
ABC.0245.4657.rvt
ABC.0245.4658.rvt


Thanks in advance!
I'm currently using Total Commander Version 10.00 64bit
kodepr
Junior Member
Junior Member
Posts: 45
Joined: 2019-09-05, 08:13 UTC

Re: Define colors by file type - only if ...

Post by *kodepr »

I have a vague idea of what regular expressions are but I have zero experience with regex.
But I'm guessing that regex might be the solution for this problem, so I gave it a go.

Code: Select all

.*\.\d{4}\.(rvt|rte|rfa|rft)
... seems to find all backup files if I do a TC-search with [x]RegEx.

And TC help file reads:
You can also select related files. For example, you would want to select all RAW image files (.cr2), but only if there is a jpg file in the same directory. This can be done with the following selection string:
*.jpg>*.cr2
This also supports more complex naming schemes. For example, if the jpg file is named IMG_1057.JPG and the raw file CRW_1057.CR2, the selection string would have to be:
*.jpg>crw*.cr2
I tried to combine this principle with the RegEx above, resulting in this TC-search with [x]RegEx:

Code: Select all

(.*)\.(rvt|rte|rfa|rft)>\1\.\d{4}\.(rvt|rte|rfa|rft)
I was hoping that a "filename" followed by a dot and 4 digits would only be selected if the same 'filename' existed without a dot and 4 digits.
In the search, any filename would be remembered by (.*) and be recalled by \1

But this search finds no files at all, so I must be doing something wrong.

Hope that helps. :?
I'm currently using Total Commander Version 10.00 64bit
User avatar
nsp
Power Member
Power Member
Posts: 1917
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Define colors by file type - only if ...

Post by *nsp »

(.*)\.(rvt|rte|rfa|rft) cover all your case as a digit or dot fall in any character <.>. The expression with \.d{4} only find backup files.
wetware05
Junior Member
Junior Member
Posts: 64
Joined: 2023-05-15, 16:10 UTC

Re: Define colors by file type - only if ...

Post by *wetware05 »

There does not seem to be any matching criteria among the group

Code: Select all

filename.rvt
Filename.0001.rvt
Filename.0002.rvt
and the group

Code: Select all

ABC.0245.rvt
ABC.0245.4657.rvt
ABC.0245.4658.rvt
Except the extension. All of the first group could be those names containing "filename" (or up to the first period from the left) contain extra characters before .rvt

Code: Select all

Filename\.\d{4}\.rvt
But that criteria doesn't work for the second group (it can't be up to the first point on the left, it can't be by "filename"), where another regex expression is required.

Code: Select all

ABC\.\d{4}\.\d{4}\.rvt
In some programming language you can create an iteration to search left and right, starting from the original filenames, looking for files with similarities, but it requires a lot of programming knowledge.
kodepr
Junior Member
Junior Member
Posts: 45
Joined: 2019-09-05, 08:13 UTC

Re: Define colors by file type - only if ...

Post by *kodepr »

2nsp

I'm quite sure that I am wrong and that you are right, but I would like to learn a little bit more about this, so feel free to tell me where I am mistaking.

I think that for simplicity I can change original code to the code below without changing what the code does:

Code: Select all

(?P<name>.*)(?P<extension>\.(rvt|rte|rfa|rft))>(?P=name)(P?<number>\.\d{4})(?P=extension)
I thought that both codes would mean that a file would only be selected/colored:
  • if it would have a syntax "name""number""extension"
  • AND if in the same folder there was a same file without "number", meaning syntax "name""extension"
So first part of code

Code: Select all

(?P<name>.*)(?P<extension>\.(rvt|rte|rfa|rft))
would indeed "list" or "preselect" all files, as you stated in your post:
Filename.rvt
Filename.0001.rvt
Filename.0002.rvt

ABC.0245.rvt
ABC.0245.4657.rvt
ABC.0245.4658.rvt


... and then the second part of the code

Code: Select all

>(?P=name)(P?<number>\.\d{4})(?P=extension)
would retain only these files:
Filename.0001.rvt
Filename.0002.rvt

ABC.0245.4657.rvt
ABC.0245.4658.rvt

... simply because there are similar files in the same folder without the "number"-part:
Filename.rvt
ABC.0245.rvt
  • could you please tell me where I am making a mistake in the process above?
  • is there another solution to get the result described in the original post
Thanks in advance!
I'm currently using Total Commander Version 10.00 64bit
wetware05
Junior Member
Junior Member
Posts: 64
Joined: 2023-05-15, 16:10 UTC

Re: Define colors by file type - only if ...

Post by *wetware05 »

hi, kodepr

My answer was rather logical, but not from my knowledge of RegEx or how to set the colors of TCM files. I can not help you. Sorry.
User avatar
nsp
Power Member
Power Member
Posts: 1917
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Define colors by file type - only if ...

Post by *nsp »

The search expression only occur on a single file ! the > character is used to "call" a saved search.

So it is not possible to achieve what you want with only regexp expression.

What you can do is to use a wdx plugin searching for sibling file in same folder.

One search will be for archive file the file ends with a . and 4 digit number and it exist a least one sibling file without the ending digits.
One search for original file it exists at least another file in the same folder with name and 4 digit number...

For the ease of definition you can use WinScriptsAdv_wdx and do some programming.

Save both search to be able to colorize with different colors.
wetware05
Junior Member
Junior Member
Posts: 64
Joined: 2023-05-15, 16:10 UTC

Re: Define colors by file type - only if ...

Post by *wetware05 »

Hi.

I have been inquiring about the color settings in Total Commander. You have to do a RegEx for the original files ABC.0245.rvt and filename.rvt and another for the copies.

In the example you've given, this works (RegEx expressions can surely be improved) for originals:

Code: Select all

<^(ABC\.0245|Filename)\.rvt$
And this for copies.

Code: Select all

<Filename\.\d{4}\.rvt|ABC\.\d{4}\.\d{4}\.rvt
They would not work outside of exposed cases.

Image: https://i.imgur.com/oDUBNrD.jpg

https://imgur.com/BqTEtpH
Post Reply