GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Display the number of lines in selected text files


#1

Inspired by code snippets provided by Kundal and TBone, here is a VBScript user command to count the number of lines in eligible selected files and display the results in a pop-up. Selected folders are ignored and selected files are tested for eligibility against a built-in list of file extensions.

To install, simply save the attached Line Counter.osp to your Directory Opus Script Addins folder. This will add a $LC command which can then be invoked from a button. See below for a sample of what the output looks like. Note that this code uses the recently added DOpus MAP object to test for eligible file extensions. You must be using at least v11.5.1 for this to work.


Regards, AB
Line Counter v1.1.osp (1.37 KB)


#2

The way you initialise the Map seems a little inefficient - creating, merging and destroying a new map for every extension. Why not just add the extensions to the map directly?

Or initialise it in the call to NewMap:

Set exts = DOpus.Newmap( "bak",1,"bat",1,"btm",1,"cmd",1,"css",1,"cue",1,"dcf",1,"dop",1,"htm",1, _ "html",1,"inc",1,"ini",1,"js",1,"lng",1,"log",1,"m3u",1,"ncl",1,"omd",1, _ "php",1,"pls",1,"rdf",1,"reg",1,"shtml",1,"sql",1,"torrent",1,"tpl",1, _ "txt",1,"url",1,"vbs",1,"xml",1)


#3

I built the map the "long way round" to make it easy to check and/or add to an ordered list of extensions. The list only gets primed once so I figured it would not add noticeably to the execution time.

Regards, AB


#4

Fair enough, it would still be a lot more efficient to add the extensions to the one map directly, e.g.:

Set exts = DOpus.NewMap
exts("bak") = 1
exts("bat") = 1
exts("btm") = 1
' etc...

Up to you though :slight_smile:


#5

Thanks. I was not aware of the direct add method which looks a lot less convoluted..... :slight_smile:

Regards, AB