' $LC ' To rename the user command simply change $LC globally to the name of your choice ' v1.0 (2014/08/18) Display line counts for eligible selected files ' v1.1 (2014/08/18) Uses a smarter way of priming the map of valid extensions Option Explicit Function OnInit(ByRef initData) ' OnInit is called by DOpus to initialize the script initData.name = "$LC (Line Counter)" initData.version= "1.1" initData.desc = "Display line counts for eligible selected files" initData.copyright = "(c) 2014 AussieBoykie" initData.default_enable = true initData.min_version = "11.5.1" ' The DOpus MAP object was added in this Beta dim cmd set cmd = initData.AddCommand() cmd.name = "$LC" ' This is the name of the command being added cmd.method = Right(cmd.name,Len(cmd.name)-1) ' Function to execute when the command is invoked cmd.desc = initData.desc cmd.label = initData.name cmd.template = "Args/M" End Function Function LC(ByRef ScriptCmdData) ' This code is executed when the added command is invoked Dim cdf, cmd, dlg, exts, files, i, n, str, tab Set cdf = ScriptCmdData.Func Set cmd = cdf.command Set dlg = cdf.Dlg With dlg .title = "Line Count" .buttons = "OK" End With str = "" ' Build map of eligible filetypes Set exts = DOpus.Newmap exts("bak") = 1 exts("bat") = 1 exts("btm") = 1 exts("cmd") = 1 exts("css") = 1 exts("cue") = 1 exts("dcf") = 1 exts("dop") = 1 exts("htm") = 1 exts("html") = 1 exts("inc") = 1 exts("ini") = 1 exts("js") = 1 exts("lng") = 1 exts("log") = 1 exts("m3u") = 1 exts("ncl") = 1 exts("omd") = 1 exts("php") = 1 exts("pls") = 1 exts("rdf") = 1 exts("reg") = 1 exts("shtml") = 1 exts("sql") = 1 exts("torrent") = 1 exts("tpl") = 1 exts("txt") = 1 exts("url") = 1 exts("vbs") = 1 exts("xml") = 1 ' Prevent selected items from being deselected With cmd .deselect=False End With Set tab = DOpus.listers(0).activetab ' Only process files, not folders Set files = tab.selected_files ' Process selected files, if there are any For i = 0 To files.count-1 ' Use DOpus MAP object functionality to test the file extension against eligible filetypes If exts.exists(mid(files(i).ext,2)) Then n = LineCount(files(i)) If n > -1 Then If Not str = "" Then str = str & vbcrlf str = str & files(i).name & " - " & n & " line" If Not n = 1 Then str = str & "s" End If End If Next ' Display line counts for eligible files If Not str = "" Then With dlg .message = str .show End With End If End Function Function LineCount(file) ' Return the number of lines in a file Dim objFS, objTS Set objFS = CreateObject("Scripting.FileSystemObject") Set objTS = objFS.OpenTextFile(file) If Not objTS.AtEndOfStream Then objTS.ReadAll LineCount = objTS.Line Else LineCount = 0 End If Set objFS = Nothing End Function