NCC Tools (never code counter tools) V1.0.1 release code-code statistics Tool

Source: Internet
Author: User

For example, save the source code as an (hta) file. Because the hta file does not have a status bar, we recommend that you save it as an html file so that you can see it under the status bar.

The NCC Scan progress. Here I set the maxloop of NCC to 3000. Therefore, when the file is counted as 3000, it will be automatically terminated to prevent the running burden from too many files in the folder.

If you like this code, pay attention to "Never Modules"

Main functions-
1. You can select a folder or a single file.
2. Select the file suffix for Statistics
3. Output information outputs the following data:
Number of files,
Number of File Code bytes,
Number of words,
Number of lines of code,
Total Code bytes
Total number of lines of code.
4. You can use SaveAs to save the code statistics as html or txt files.Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<! Doctype html public "-// W3C // dtd html 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> NCC Tools-http://www.never-online.net </title>
<Hta: application id = "NCC"
Applicationname = "NCC application"
Border = "thin"
Borderstyle = "normal"
Caption = "yes"
Icon = "http://www.never-online.net/images/icon.ico"
Maximizebutton = "no"
Minimizebutton = "yes"
Showintaskbar = "no"
Singleinstance = "yes"
Sysmenu = "yes"
Version = "1.01"
WindowState = "normal"/>
<Meta http-equiv = "ImageToolbar" content = "no"/>
<Meta name = "author" content = "BlueDestiny, never-online"/>
<Meta name = "keywords" content = "never modules, Mozilla CSS, C #,. net, Refercence, BlueDestiny, never-online, www.never-online.net"/>
<Meta name = "description" content = "BlueDestiny, never-online"/>
<Meta name = "title" content = "never code counter (NCC)-http://www.never-online.net"/>
<Meta name = "creator. name" content = "Genius Lau, never-online, blueDestiny"/>
<Style type = "text/css" media = "all" title = "Default">
Body {background-color: buttonface ;}
Body, td, input {font: 9pt tahoma ;}
H1 {text-align: center; font-weight: bold; font-family: tahoma; font-size: 16pt ;}
Fieldset {height: 300px ;}
Legend {font-weight: bolder ;}
. Btn {border-left: 4px solid #444; border-top: 1px solid #444; border-bottom: 1px solid #444; border-right: 1px solid #444 ;}
. Two {width: 200px ;}
. Txt {border: 1px solid #444 ;}
. File {display: none; width: 300px; border-left: 4px solid #444; border-top: 1px solid #444; border-bottom: 1px solid #444; border-right: 1px solid #444 ;}
# Loading {display: none; filter: alpha (opacity = 70); border: 1px solid #444444; background-color: appworkspace; color: # ffffff; width: 300px; font-size: 13px; font-weight: bold; font-family: arial; padding: 10px; position: absolute; top: 0; left: 0 ;}
# Left {line-height: 200%; width: 50%; padding: 20px ;}
# Left ul {margin: 0 0 0 10px ;}
# Left li {list-style-type: decimal; margin: 20px 10px 15px 10px ;}
# Footer {font-size: 11px; text-align: center ;}
# Right {padding: 20px; width: 50% ;}
# OutputWrapper {padding: 10px ;}
</Style>
<Script type = "text/javascript">
// <! [CDATA [

// ================================================ ========================================================== ==========
//
// Module: NCC-never code counter V1.01 beta
// Script by: never-online, blueDestiny
// Updated: 2006-6-25
// Copyright: Miracle technology all reserved
// Website: http://www.never-online.net
// Email: blueDestiny@126.com
// Blog: http://blog.csdn.net/blueDestiny, http://blog.never-online.net/
// Comment: Permission given to use this script in ANY kind of applications if
// Header lines are left unchanged.
//
// ================================================ ========================================================== ==========

// ================================================ ========================================================== ======
// Ultity Function
Var doc = document, wnd = window;
String. prototype. trim = function () {return this. replace (/(^ \ s *) | (\ s * $)/g ,'');};
Array. prototype. push = function (x) {this [this. length] = x ;};
Array. prototype. pop = function () {return this [this. length-1] ;};
// ================================================ ========================================================== ======
Var NCC =
{
// Private Variables
_ Maxloop: 3000,
_ Versions: "1.02 beta ",
_ Author: "BlueDestiny, never-online ",
_ WebURI: "http://www.never-online.net ",
_ Lines: {"total": 0 },
_ Bytes: {"total": 0 },
_ Files: {"total": 0 },
_ Words: {"total": 0 },
_ Error :{},
_ FilesExts: "cs, js, asp, xml, aspx ",
_ FsoObj: new ActiveXObject ("Scripting. FileSystemObject ")
// Make sure Your fso activeXObject is availd. otherwise can not runing next code
};
// Public Functions API
NCC. splash = function ()
{

};
NCC. init = function ()
{
Var fileDlgObjStr = '<object id = "filepathDlg "'
+ 'Width = "0px" height = "0px "'
+ 'Classid = "CLSID: F9043C85-F6F2-101A-A3C9-08002B2F49FB "'
+ 'Codebase = "http://activex.microsoft.com/controls/vb5/comdlg32.cab">'
+ '</Object> ';
Var folderDlgObjStr = '<object id = "folderpathDlg "'
+ 'Classid = "CLSID: 13709620-C279-11CE-A49E-444553540000 "'
+ 'Width = "0" height = "0">'
+ '</Object> ';
Var loadingObjStr = '<div id = "loading"> </div> ';
Doc. body. insertAdjacentHTML ("beforeEnd", fileDlgObjStr );
Doc. body. insertAdjacentHTML ("beforeEnd", folderDlgObjStr );
Doc. body. insertAdjacentHTML ("beforeEnd", loadingObjStr );
}
NCC. chkFileExts = function (filenameStr)
{
Var a = this. _ filesExts. trim (). split (",");
Var f = this. getFileExts (filenameStr );
For (var I = 0; I <a. length; I ++)
If (f. toLowerCase () = a [I]. toLowerCase () return true;
Return false;
};
NCC. output = function (wrapperID)
{
Var k, x; x = [];
X. push ("------------- Files -------------");
// -- Part of files --
For (k in this. _ files)
X. push ("[" + k + "]:" + this. _ files [k] + "");
// -- Part of words --
X. push ("------------- Words -------------");
For (k in this. _ words)
X. push ("[" + k + "]:" + this. _ words [k] + "");
// -- Part of bytes --
X. push ("------------- Bytes -------------");
For (k in this. _ bytes)
X. push ("[" + k + "]:" + this. _ bytes [k] + "");
// -- Part of lines --
X. push ("------------- Lines -------------");
For (k in this. _ lines)
X. push ("[" + k + "]:" + this. _ lines [k] + "");
X = x. join ("\ n ");
If (wrapperID ){
Var a = doc. all (wrapperID), t = a. tagName. toLowerCase ();
If (! A) return wnd. alert ("HTMLElement ID \" "+ wrapperID +" \ "is not valid! ");
If (t = "input" | t = "textarea") a. value = x;
Else a. innerHTML = x. replace (/\ n/, "<br/> ");
}
Return x;
};
NCC. saveAs = function (elIdorStr)
{
Var dlg = doc. all ("filepathDlg ");
Var a = doc. all (elIdorStr );
If (){
Var t = a. tagName. toLowerCase ();
Var fileStr = (t = "input" | t = "textarea ")? A. value: a. innerHTML. replace (/<br (\/)?> /G, "\ n ");
} Else {
FileStr = elIdorStr;
}
Dlg. cancelError = true;
Try {
Dlg. filter = "Text Files (*. txt) | *. txt | HTM Files (*. htm) | *. htm ";
Dlg. showSave ();
Var f = this. _ fsoObj. CreateTextFile (dlg. filename, true );
F. write (fileStr );
F. Close ();
} Catch (ex ){};
};
NCC. setFilesExt = function (filesExtsStr)
{
This. _ filesExts = filesExtsStr;
Return true;
};
NCC. getFilesExts = function ()
{
Return this. _ filesExts;
};
NCC. getFileExts = function (filenameStr)
{
Var a = filenameStr. split (".");
Return a [a. length-1]. toLowerCase (); // a. pop ()
};
NCC. selectSingleFile = function ()
{
Var dlg = doc. all ("filepathDlg ");
Var fps = doc. all ("filepathStr ");
Var fes = this. _ filesExts;
Var filename = "", filter = "", arr = [];
Arr = fes. trim (). split (",");
For (var I = 0; I <arr. length; I ++)
Filter + = arr [I]. toUpperCase () + "Files (*. "+ arr [I] +") | *. "+ arr [I] +" + (I = arr. length-1? "": "| ");
Dlg. cancelError = true;
Try {
Dlg. filter = filter;
Dlg. showOpen ();
Filename = dlg. filename;
} Catch (ex ){};
If (filename. trim () = "") return false;
Fps. value = filename;
If (! This. chkFileExts (filename) return wnd. alert ("File Extension name \" "+ filename +" \ "is not valid! ");
Return filename;
};
NCC. selectFolder = function ()
{
Var dlg = doc. all ("folderpathDlg ");
Try {
Var pathObj = dlg. browseForFolder (0, "Please Select Folder:", 0 );
Var pathStr = pathObj. parentFolder. parseName (pathObj. Title). path;
Return pathStr;
} Catch (ex) {return false };
};
NCC. countFolder = function (folderpathStr)
{
Var ldg = doc. all ("loading ");
With (ldg. style ){
Display = "block ";
Top = parseInt (doc. body. clientHeight-ldg.offsetHeight)/2 );
Left = parseInt (doc. body. clientWidth-ldg.offsetWidth)/2 );
}; Ldg. innerHTML = "<div align = \" center \ "> Now Counting... </div> ";
Wnd. status = "NCC Counting ...";
If (! This. _ fsoObj. FolderExists (folderpathStr )){
This. countSingleFile (folderpathStr );
} Else {
Var cnt = 0;
Function iterator (folderpathStr ){
Var a = NCC. _ fsoObj. getFolder (folderpathStr );
Var e = new Enumerator (a. files)
For (;! E. atEnd (); e. moveNext ()){
NCC. countSingleFile (e. item ());
If (cnt ++> = NCC. _ maxloop) return;
}

Var f = new Enumerator (a. subFolders)
For (;! F. atEnd (); f. moveNext ()){
Iterator (f. item ());
If (cnt ++> = NCC. _ maxloop) return;
}
}
Iterator (folderpathStr );
}
Ldg. innerHTML = "<div align = \" center \ "> NCC Count Completely. </div>"
Wnd. status = "NCC Count Completely .";
Wnd. setTimeout (function () {ldg. style. display = "none" ;}, 3000 );
};
NCC. countSingleFile = function (filepathStr)
{
Var x, a, f, e;
Var ldg = doc. all ("loading ");
If (! This. _ fsoObj. FileExists (filepathStr) return false;
F = this. _ fsoObj. GetFile (filepathStr );
If (this. chkFileExts (f. name ))
{
Var o = f. openAsTextStream (1 );
If (o. atEndOfStream) {x = "" ;}else {x = o. ReadAll ();}
X = x. replace (/(\ n | \ r) +/mg, "$1 ");
A = x. split ("\ n ");
E = this. getFileExts (f. name );
This. _ bytes ["total"] + = x. length;
This. _ bytes [e]? This. _ bytes [e] + = x. length: this. _ bytes [e] = x. length;
This. _ lines ["total"] + = a. length;
This. _ lines [e]? This. _ lines [e] + = a. length: this. _ lines [e] = a. length;
A = x. replace (/(\ s | \ t |) +/g, ""). split ("");
This. _ words ["total"] + = a. length;
This. _ words [e]? This. _ words [e] + = a. length: this. _ words [e] = a. length;
This. _ files ["total"] ++;
This. _ files [e]? This. _ files [e] ++: this. _ files [e] = 1;
}
Wnd. status = "NCC (\" "+ f. path + "\")";
Ldg. innerHTML = "now count \" "+ f. name + "\"."
Return this. chkFileExts (f. name)
};
NCC. formatSingleFile = function (filepathStr)
{

};
// ================================================ ========================================================== ======
Function window. onload (){
NCC. init ();
Wnd. resizeTo (800,480 );
Doc. all ("outputWrapper"). value = "";
SetFilesExts (); // setFilesExts. call (this );
}
Function setFilesExts (){
Doc. all ("filesExts"). value = NCC. getFilesExts ();
}
Function output (){
/*
Var e = event. srcElement;
Var a = doc. body. all;
For (var I = 0; I <a. length; I ++ ){
If (a [I]. tagName. toLowerCase () = "input "){
If (a [I]! = E) a [I]. disabled = true;
}
}
*/
NCC. setFilesExt (doc. all ("filesExts"). value)
NCC. countFolder (doc. all ('filepathstr'). value );
NCC. output ('outputwrapper ');
}
Function changeFileExt (){
Var groupfileExts = doc. all ("groupfileExt ");
Var fileExtStr = [];
For (var I = 0; I <groupfileExts. length; I ++ ){
If (groupfileExts [I]. checked)
FileExtStr. push (groupfileExts [I]. value );
}
NCC. setFilesExt (fileExtStr. join (","));
SetFilesExts ();
}
Function selectSingleFile (val ){
If (! NCC. selectSingleFile () return "";
Doc. all (val). value = NCC. selectSingleFile ();
}
Function selectFolder (val ){
Var a = NCC. selectFolder ();
If (a = false) return "";
Doc. all (val). value =;
}
Function saveAs (){
NCC. saveAs ('outputwrapper ');
// NCC. saveAs (NCC. output ());
}
//]>
</Script>
</Head>
<Body id = "www.never-online.net">
<H1> NCC (never code counter) tools-http://www.never-online.net
<Fieldset>
<Legend>-Application NCC (never code counter)-</legend>
<Table width = "100%" border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<Td align = "left" valign = "top" id = "left">
<Ul>
<Li>
<Input name = "filepathStr" type = "text" class = "txt" value = "type your file or folder path" size = "30">
<Input class = "btn" type = "button" value = "FILE" onclick = "selectSingleFile ('filepathstr')"/>
<Input class = "btn" type = "button" value = "FOLDER" onclick = "selectFolder ('filepathstr')"/>
</Li>
<Li>
<Input name = "groupfileExt" value = "asp" type = "checkbox" checked onclick = "changeFileExt ()"/>
. Asp
<Input name = "groupfileExt" value = "js" type = "checkbox" checked onclick = "changeFileExt ()"/>
. Js
<Input name = "groupfileExt" value = "xml" type = "checkbox" checked onclick = "changeFileExt ()"/>
. Xml
<Input name = "groupfileExt" value = "aspx" type = "checkbox" checked onclick = "changeFileExt ()"/>
. Aspx
<Input name = "groupfileExt" value = "cs" type = "checkbox" checked onclick = "changeFileExt ()"/>
. Cs
<Br/>
<Input name = "filesExts" type = "text" class = "txt" id = "filesExts" value = "" size = "40">
</Li>
<Li>
<Input class = "btn two" type = "button" value = "Output Information" onclick = "output ()"/>
<! -- Not complete <input name = "button" type = "button" class = "btn" onclick = "NCC. format ();" value = "Format Code"/> -->
</Li>
<Li>
<Input class = "btn two" type = "button" value = "Information Save As" onclick = "saveAs ();"/>
</Li>
</Ul>
<Div id = "footer">
<P>
NCC V1.01 beta Power By BlueDestiny, never-online
<Br/>
More code please visit <a href = "http://www.never-online.net" target = "_ blank" title = "visit my site"> http://www.never-online.net </a>
</P>
</Div>
</Td>
<Td align = "left" valign = "top" id = "right">
<Fieldset>
<Legend>-Output Information-</legend>
<Textarea id = "outputWrapper" style = "border: 0; background-color: buttonface; width: 96%; height: 100%;"> </textarea>
</Fieldset>
</Td>
</Tr>
</Table>
</Fieldset>
</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.