浏览文件神器!且可以计算所有文件代码的行数!
2014-09-12 16:25
441 查看
1. [图片] 201312051416305445.jpg
2. [代码]demo
//http://www.codepearl.com
header("Content-type: text/html; charset=UTF-8");
include("class.lineCount.php");
?>
<HTML>
<HEAD>
<TITLE>Source Code Count</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?
$lineCount = new lineCount;
// If no directory is given, it will use the directory of the script
$lineCount->dir="../linecount";
// Use this method to output the summary and list of files to the page
// You can customize the HTML from within the class
$lineCount->summary(1);
// Use this method to get the totals as an associative array:
$totals = $lineCount->summary(0);
# echo $totals["folders"] / $totals["files"] / $totals["lines"]
?>
</BODY>
</HTML>
3. [代码]操作类
//http://www.codepearl.com
header("Content-type: text/html; charset=UTF-8");
class lineCount {
// Don't modify these
var $x = 0;
var $cnt = array();
// Files to include in the count
var $ext = array("php","phtml","php3","inc","js","html","htm","css","doc");
// If no directory is set, the directory of the script will be used
var $dir = "";
function countLines($dir) {
if (is_dir($dir)) {
$dir=iconv("gb2312","GBK",$dir);
if ($handle = opendir($dir)) {
// Loop through files
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filePath = $dir."/".$file;
if (is_dir($filePath)) {
// Item is another folder, call the function again
$this->countLines($filePath);
} else {
// Item is a file, get some info about it
$fileName = explode("/",$filePath);
$fileDir = $fileName[(count($fileName)-2)];
$fileName = $fileName[(count($fileName)-1)];
$fileExt = explode(".",$fileName);
$fileExt = $fileExt[(count($fileExt)-1)];
if (in_array($fileExt,$this->ext)) {
// Open the file, get line count
$fp = fopen($filePath, "r");
$buffer = rawurlencode(fread($fp, filesize($filePath)));
$buffer = explode("%0A", $buffer);
$numLines = count($buffer);
fclose($fp);
// Add the information to our count array
$this->cnt[$this->x]['dir'] = $dir;
$this->cnt[$this->x]['file'] = $fileName;
$this->cnt[$this->x]['count'] = $numLines;
$this->x++;
}
}
}
}
closedir($handle);
} else {
return false;
}
} else {
return false;
}
}
function summary($output=1) {
// $output
// 1 to generate a summary and file list
// 0 to get an associative array with the totals
if (!(is_dir($this->dir))) {
// No directory given, use document root
$this->dir = $_SERVER['DOCUMENT_ROOT'];
}
$this->countLines($this->dir);
$listOutput = "";
$totalLines = 0;
$usedDir = array();
for ($i=0;$i<count($this->cnt);$i++) {
$totalLines += $this->cnt[$i]['count'];
if (!(in_array($this->cnt[$i]['dir'],$usedDir))) {
if ($output==1) {
$listOutput .= " <TR>\n";
$listOutput .= " <TD COLSPAN=\"2\" BGCOLOR=\"#EEEEEE\" WIDTH=\"100%\" ALIGN=\"left\" STYLE=\"border-bottom: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC\"><FONT STYLE=\"font-family: arial; font-size: 9pt\"><B>".iconv("GB2312","UTF-8",$this->cnt[$i]['dir'])."</B></FONT></TD>\n";
$listOutput .= " </TR>\n";
}
$usedDir[] = $this->cnt[$i]['dir'];
}
if ($output==1) {
$listOutput .= " <TR>\n";
$listOutput .= " <TD WIDTH=\"80%\" ALIGN=\"left\" STYLE=\"border-bottom: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC\"><FONT STYLE=\"font-family: arial; font-size: 9pt\">".iconv("GB2312","UTF-8",$this->cnt[$i]['file'])."</FONT></TD>\n";
$listOutput .= " <TD WIDTH=\"20%\" ALIGN=\"center\" STYLE=\"border-bottom: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC\"><FONT STYLE=\"font-family: arial; font-size: 9pt\">".number_format($this->cnt[$i]['count'])."</FONT></TD>\n";
$listOutput .= " </TR>\n";
}
}
$totalFiles = number_format(count($this->cnt));
$totalLines = number_format($totalLines);
$totalFolders = number_format(count($usedDir));
if ($output==1) {
print "<CENTER>\n";
print "<B><FONT STYLE=\"font-family: arial; font-size: 13pt\">".$this->dir."</B></FONT><BR><BR>\n\n";
print "<TABLE WIDTH=\"85%\" BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"0\">\n";
print " <TR>\n";http://www.huiyi8.com/qinglv/
print " <TD WIDTH=\"10%\" ALIGN=\"left\"><FONT STYLE=\"font-family: arial; font-size: 11pt\"><B>简述:</B> ".$totalFolders."文件夹, ".$totalFiles."文件, ".$totalLines." 行代码</FONT></TD>\n";
print " </TR>\n";情侣图片
print "</TABLE>\n";
print "<TABLE WIDTH=\"85%\" CELLPADDING=\"6\" CELLSPACING=\"1\" STYLE=\"border-top: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC\">\n";
print " <TR>\n";
print " <TD WIDTH=\"80%\" ALIGN=\"left\" BGCOLOR=\"#4C6177\" STYLE=\"border-bottom: 1px solid #182C41; border-right: 1px solid #182C41\"><FONT STYLE=\"font-family: arial; font-size: 11pt; color: #FFFFFF\"><B>文件名/目录</B></FONT></TD>\n";
print " <TD WIDTH=\"20%\" ALIGN=\"center\" BGCOLOR=\"#4C6177\" STYLE=\"border-bottom: 1px solid #182C41; border-right: 1px solid #182C41\"><FONT STYLE=\"font-family: arial; font-size: 11pt; color: #FFFFFF\"><B>代码行数</B></FONT></TD>\n";
print " </TR>\n";
print $listOutput;
print "</TABLE>\n";
print "<TABLE WIDTH=\"85%\" BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"0\">\n";
print " <TR>\n";
print " <TD WIDTH=\"10%\" ALIGN=\"left\"><FONT STYLE=\"font-family: arial; font-size: 11pt\"><B>简述:</B> ".$totalFolders."文件夹, ".$totalFiles."文件, ".$totalLines."行代码</FONT></TD>\n";
print " </TR>\n";
print "</TABLE>\n";
print "</CENTER>\n";
} else {
return array("files"=>$totalFiles,"lines"=>$totalLines,"folders"=>$totalFolders);
}
}
}
?>
相关文章推荐
- [原创]Python小工具 —— 计算 文件 或 文件夹及其所有子文件夹中所有文件 的 代码行数
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)(示例代码下载)
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)(示例代码下载)
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)(示例代码下载)
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)(示例代码下载)
- python3 计算文件夹中所有py文件里面代码行数,注释行数,空行数
- 计算目录下所有程序文件代码行数
- JAVA作业——输入指定文件,计算代码行数
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)
- 利用正则表达式统计某个某个文件夹下所有java文件的 空格行数、注释行数、和代码行数
- 使用Eclipse可以方便的统计工程或文件的代码行数,
- 计算一个项目工程中所有包下面的代码行数
- 有一个很大的整数list,需要求这个list中所有整数的和,写一个可以充分利用多核CPU的代码,来计算结果(转)
- Linux 下使用 wc 统计文件夹下所有文件的代码行数(包括子目录)
- C++ 一个统计文件夹下所有代码文件行数的小工具
- IOS学习--Foundation--计算文件中得代码行数(小练习)
- JAVA作业—从命令行输入两个参数打开文件并计算代码行数 .
- linux下shell统计文件目录下所有代码行数
- 计算一个目录下的所有.java文件的行数
- 【C++】计算所有小于N的勾股数组合,可以写入txt文件保存,每组占一行。