Script Content Plugin

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, Hacker, petermad, Stefan2

User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Some problems with three digits ..

Post by *Peter »

Hello

it's not Monday, but I could test it.

OK:

Code: Select all

1.txt -> 001.txt
01.txt -> 001.txt
12.txt -> 012.txt
R1.txt -> R001.txt
r12.txt -> r012.txt
[/color]
not OK:

Code: Select all

123.txt -> 1023.txt
R123.txt -> R1023.txt
[/color]

In my case, I need only a solution for the "numbered filenames" (1.txt, 11.txt, 111.txt, ..); but maybe others need a solution for the combined filenames (numbers + letters)?

Who can help?

Have a nice sunday.

Peter
TC 10.xx / #266191
Win 10 x64
User avatar
Sheepdog
Power Member
Power Member
Posts: 5150
Joined: 2003-12-18, 21:44 UTC
Location: Berlin, Germany
Contact:

Re: Some problems with three digits ..

Post by *Sheepdog »

Peter wrote: not OK:

Code: Select all

123.txt -> 1023.txt
R123.txt -> R1023.txt
[/color]
Guess it should be:

Code: Select all

123.txt -> 123.txt
R123.txt -> R123.txt
Right?

sheepdog
"A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete fools."
Douglas Adams
User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

Yes,

123.txt should stay unchanged "123.txt", but it is changed to 1023.txt.

R123.txt should stay unchanged "R123.txt", but it is changed to R1023.txt.

Peter
TC 10.xx / #266191
Win 10 x64
User avatar
Sheepdog
Power Member
Power Member
Posts: 5150
Joined: 2003-12-18, 21:44 UTC
Location: Berlin, Germany
Contact:

Post by *Sheepdog »

Then you'll have to add a third line:

Code: Select all

re.Pattern="(.*)(\d\.)"
b="$100$2"
If re.test(filename) then content = re.Replace(filename,b)

re.Pattern="(.*)(\d{2}\.)"
b="$10$2"
If re.test(filename) then content = re.Replace(filename,b)

re.Pattern="(.*)(\d{3}\.)"
b="$1$2"
If re.test(filename) then content = re.Replace(filename,b)
wich tests if there are 3 numbers in a row and then leaves the filebname untouched.
As far as I heve tested it works now even with more numbers like file3004.ext because there are as well 3 numbers in a row.

sheepdog
"A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete fools."
Douglas Adams
User avatar
van Dusen
Power Member
Power Member
Posts: 684
Joined: 2004-09-16, 19:30 UTC
Location: Sinzig (Rhein), Germany

Post by *van Dusen »

Another alternative:

Code: Select all

re.Pattern="((\D+)|^)(\d{1})(\D+|$)"
b="$100$3$4"
If re.test(filename) then content = re.Replace(filename,b)

re.Pattern="((\D+)|^)(\d{2})(\D+|$)"
b="$10$3$4"
If re.test(filename) then content = re.Replace(filename,b)
The regex works on files like [X]9[X][.ext] and [X]99[X][.ext]:

9[.ext]; 99[.ext]; 999[.ext]
=> 009[.ext]; 099[.ext]; 999[.ext]

X9[.ext]; X99[.ext]; X999[.ext]
=> X009[.ext]; X099[.ext]; X999[.ext]

9X[.ext]; 99X[.ext]; 999X[.ext]
=> 009X[.ext]; 099X[.ext]; 999X[.ext]

X9X.ext; X99X.ext; X999X.ext
=> X009X[.ext]; X099X[.ext]; X999X[.ext]


The regex will find only the first occurence of "9"/"99", so unfortunately it doesn't work on files with more than one occurence of "9"/"99". For instance:

X9X9X[.ext]; X99X99X[.ext]; X999X999X[.ext]
=> X009X9X[.ext]; X099X99X[.ext]; X999X999X[.ext]
User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

Thanks to Berlin

I will test it, but I am sure that it will work fine.

Code: Select all

re.Pattern="(.*)(\d\.)"
b="$100$2"
If re.test(filename) then content = re.Replace(filename,b)
For better understanding the code, can you explain me the second line?

I think,

re.Pattern="(.*)(\d\.)" or re.Pattern="(.*)(\d{2}\.)"

means:
"Take any filename (.*) with one number (\d\.) or two numbers (\d{2}\.)"

but what is the exact explanation of the second line(s)?

Peter

BTW: After my last reply I got no information by "forumadmin" that there are new postings :(
TC 10.xx / #266191
Win 10 x64
User avatar
van Dusen
Power Member
Power Member
Posts: 684
Joined: 2004-09-16, 19:30 UTC
Location: Sinzig (Rhein), Germany

Post by *van Dusen »

In re.Pattern (the search-expression):

<.> ... A dot is a placeholder for one arbitrary character
<\.> ... One dot (because <.> is a meta character, you need a preceding <\> as escape character for searching a dot itself)
<*> ... An asterisk is an iterator: the preceding expression occurs zero, one or more times
<\d> ... One digit (0..9)
<{}> ... The curly braces are part of an iterator: <{n}>: The preceding expression occurs exactly n times; <{n,}>: The preceding expression occurs at least n times; <{,m}>: The preceding expression occurs at most m times; <{n,m}>: Self-explaining
<()> and corresponding <$n> ... Parenthesis groups expressions in the search part. In the replace expression you can use <$n> to refer these groups. <$1> stands for the first group, <$2> for the second and so on.


Search expression "(.*)(\d\.)" means:

Search for each part of the filename, which contains zero, one or more arbitrary characters (=group $1) , followed by one digit, followed by a dot (=group $2)


Replace expression "$100$2" means:

Take the character(s), which were found by "(.*)" (="$1"), add two "0" (="00") and take the characters, which were found by "(\d\.)" (="$2")


See TC help 3j, dialogue box MRT, regular expressions for further details. But be aware, that TC handles regular expressions somewhat different from scriptwdx-plugin...
User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

van Dusen

thanks - for me it is rather clear now.

Grüsse nach Berlin

Peter
TC 10.xx / #266191
Win 10 x64
User avatar
van Dusen
Power Member
Power Member
Posts: 684
Joined: 2004-09-16, 19:30 UTC
Location: Sinzig (Rhein), Germany

Script: Properties of LNK- and URL-shortcuts

Post by *van Dusen »

Since the FileDesc content plugin isn't allowed to use the WhereIsIt FileDescriptions-DLL, it isn't possible anymore to show the properties of LNK-shortcuts... or do I miss anything?

However, this script extracts the properties of LNK- and URL-shortcuts:

Code: Select all

'*** readlink, van Dusen, 26.12.2005
'Script for Script Content Plugin
'(c)Lev Freidin, 2005
'http://www.totalcmd.net/plugring/script_wdx.html
'http://wincmd.ru/plugring/script_wdx.html

Dim oFSO, oLink, sProperty

Set oFSO = CreateObject("Scripting.FileSystemObject")
sExt = lcase(oFSO.GetExtensionName(filename))
Set oFSO = Nothing

vResult = ""

if sExt = "lnk" or sExt = "url" then

      Set Shell = CreateObject("WScript.Shell")
      Set oLink = Shell.CreateShortcut(filename)

      sProperty = oLink.TargetPath
      if sProperty <> "" then vResult = vResult & sProperty

      if sExt = "lnk" then
      
         sProperty = oLink.Arguments      
         if sProperty <> "" then vResult = vResult & " " & sProperty
   
         sProperty = oLink.WorkingDirectory
         if sProperty <> "" then vResult = vResult & "  •  WkDir: " & sProperty
   
         sProperty = oLink.Description
         if sProperty <> "" then vResult = vResult & "  •  Desc: " & sProperty

         sProperty = oLink.HotKey
         if sProperty <> "" then vResult = vResult & "  •  HKey: " & sProperty

         sProperty = oLink.IconLocation
         if sProperty <> "" then vResult = vResult & "  •  Icon: " & sProperty

         sProperty = oLink.WindowStyle
         if sProperty <> "" then vResult = vResult & "  •  Style: " & sProperty
      
      end if

      Set oLink = Nothing
      
end if
   
content = vResult
User avatar
tbeu
Power Member
Power Member
Posts: 1336
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

Hi Lev,

what do you think about to alternatively display the script content column on demand (ft_ondemand) or as background process (ft_delayed)?

Thanks,
tbeu
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
mbirth
Junior Member
Junior Member
Posts: 32
Joined: 2005-12-12, 08:21 UTC
Location: DE, Berlin

TrID as Content-Plugin

Post by *mbirth »

If you want to get a quick overview on your unknown files, try this script, which shows a column with the TrID identification. (TrID Homepage)

File wdx_TrID.js:

Code: Select all

/****************************************************************************
* TrID Content Script                                                       *
* by Markus Birth <mbirth@webwriters.de>                                    *
* for ScriptWDX by Lev Freidin                                              *
* using TrID - the File Identifier from http://mark0.net/soft-trid-e.html   *
****************************************************************************/

tridexe = 'c:\\program files\\totalcmd\\Tools\\TrID\\trid.exe';
cutpercent = false;     // set to "true" to cut off the percentage of match

if (!filename) {
  var filename = 'c:\\progra~1\\totalcmd\\Tools\\TrID\\TrIDDefs.TRD';
  var debug = true;
} else {
  var debug = false;
}

content = '';

var WSS = new ActiveXObject("WScript.Shell");
var FSO = new ActiveXObject("Scripting.FileSystemObject");

var tmp = FSO.GetParentFolderName(tridexe)+'\\'+FSO.GetTempName();
var cmd = '"'+tridexe+'" "'+filename+'" -r:1 >"'+tmp+'"';
//cmd = 'cmd /C "'+cmd.replace(/\"/g, '\\"')+'"';   // had to put cmdline in quotes and escape quotes in cmdline
cmd = 'cmd /C "'+cmd+'"';
FSO.CreateTextFile(tmp);
WSS.Run(cmd, 0, true);
//result = WSS.Exec(cmd);
var res = '';
var nextisit = false;

if (debug) WSS.Popup('Command is: '+cmd+'\nTempfile is: '+tmp, 0, 'Debug output', 0);
output = FSO.OpenTextFile(tmp, 1);
while (!output.AtEndOfStream) {
  if (nextisit) {
    test = output.ReadLine();
    if (test.length > 0) res = test;
  } else {
    test = output.ReadLine();
    if (test.substr(0, 27) == 'Collecting data from file: ') {
      nextisit = true;
    }
  }
}
output.Close();
FSO.DeleteFile(tmp);

if (cutpercent) {
  res = res.substr(res.indexOf('% ')+2);
}

content = res;

if (debug) WSS.Popup('Result is: '+content, 0, 'Debug output', 0);

While coding this piece, I found this one which does the same thing without Windows Scripting Host but also need the external TrID.exe .

Cheers,
-mARKUS

P.S.: One word of warning: Don't try this script on the directory where TrID is located since it creates temporary files there. If TotalCmd is set to automagically display these new files, you'll end up in an endless loop of TrID analyzing this new file, thus creating a new temporary file and TotalCmd running TrID on that new file, etc. .... just don't do it!

P.P.S.: Oh, and you don't want to try it on a directory with thousands of files since TrID needs its time and you'll have to wait ages for it to complete.
PyTyus
Junior Member
Junior Member
Posts: 6
Joined: 2007-08-15, 10:00 UTC
Location: Czech Republic

Post by *PyTyus »

Lev,

Thank you for this very useful plugin. I found it about a month ago and have been using it on a daily basis since.

I was particularly looking for some content plugin which would return the values from inside of a file and I could specify the search criteria myself. Even after extensive search in TC forum didn't find anything suitable except for Script Content Plugin.

I am attaching the code I use for look up values based on some regular expression pattern:

Code: Select all

'Script for Script Content Plugin (c)Lev Freidin, 2005

'Script author: Petr Judl
'Searches inside of a file and looks for a value specified by regular expression

Set fso = CreateObject("Scripting.FileSystemObject") 
Set oTextStream = fso.OpenTextFile(filename) 
Set objRegEx = New RegExp

With objRegEx
     ' This property defines the regular expression or search pattern string that is to be matched during the search
     .Pattern    = "8\d{7}"
     .Global     = False ' False signifies that a search should only find the first occurrence of a match
     .IgnoreCase = False ' False signifies that a search should be case-sensitive
End With

' set how long string should be read
' (e.g. if you know the searched string can only be at the beginning of the file, there is no need to read the whole file)
If not oTextStream.AtEndOfStream Then sText = oTextStream.Read(210)

Set Matches = objRegEx.Execute(sText)

'set Match = Matches(0)
If Matches.Count > 0 Then
    content = Matches(0).Value
Else
    content = "" ' fill whatever you need to return if the searched value was not found
End If

oTextStream.Close

And I also have a question :wink:

I don't need multiple custom columns in one panel, but I would love to be able to set up multiple custom views where each of them would have a Script Content Plugin column, but using different scripts.
Is it somehow possible to achieve this? Or any plans for implementing this functionality? It looks like the script.ini file is made with this approach in mind, but I think it's not possible to achieve this at the moment, right?

Also, nice to have feature would be ability to pass some variables from outside to a called script.

PT
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

readme.txt wrote:If you want to create additional columns of the plugin then create a copy of a plugin directory. Rename wdx file, do not rename ini file. Register new wdx as new plugin and add a new column.
I switched to Linux, bye and thanks for all the fish!
PyTyus
Junior Member
Junior Member
Posts: 6
Joined: 2007-08-15, 10:00 UTC
Location: Czech Republic

Post by *PyTyus »

SanskritFritz: Actually I am aware of this. I was rather wondering if this can be achieved some other way, so I only need to edit one ini file.
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

Ah ok. I dont know if there is any other way.
Thanks for the script by the way!
I switched to Linux, bye and thanks for all the fish!
Post Reply