代码行数统计(指定目录下所有文件的Line)
- 遍历文件夹计算文件行数(Windows)
主要使用的是 FindFirstFile、 FindNextFile函数寻找子目录下的文件,使用 WIN32_FIND_DATA(文件属性) 结构体
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h> char localpath[250] = {0};
int AllCodeLine = 0;
int fileNum = 0; void WriteErrToOutputFlie(char *inputpath , char *ErrMessage)
{
FILE *fd;
char buffer[250] = {0}; sprintf(buffer, "%s\\output.txt", inputpath); fd = fopen(buffer, "w");
fputs(ErrMessage, fd);
} int CreteOutputFlie(char *inputpath)
{
FILE *fd;
char buffer[250] = {0}; sprintf(buffer, "%s\\output.txt", inputpath); fd = fopen(buffer, "w+");
if(NULL == fd)
{
return -1;
} fclose(fd);
return 0;
} int File_Check_operation(char *inputpath, char *outputpath, FILE* writefd)
{
HANDLE hFile;
FILE *readfd;
int flieline = 0;
char ErrMess[250] = {0};
char buffer[250] = {0};
char szSubPath[250] = {0};
WIN32_FIND_DATA pNextInfo; sprintf(buffer, "%s\\*", inputpath); if( (NULL == inputpath) || (NULL == outputpath))
{
return -1;
} hFile = FindFirstFile(buffer,&pNextInfo);
if(!hFile)
{
return -2;
} while(FindNextFile(hFile,&pNextInfo)) //loop local path,find subpath
{
if(strcmp(pNextInfo.cFileName, "..") == 0 || strcmp(pNextInfo.cFileName, ".") == 0 || strcmp(pNextInfo.cFileName, "output.txt") == 0) // filter . and ..
{
continue;
} if(pNextInfo.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) //Check file is a directory
{
sprintf(szSubPath, "%s\\%s", inputpath, pNextInfo.cFileName);
File_Check_operation(szSubPath, outputpath, writefd);
}
else
{
//except image flie
if( strcmp( &(pNextInfo.cFileName[strlen(pNextInfo.cFileName) - 3]), "png") == 0 ||
strcmp( &(pNextInfo.cFileName[strlen(pNextInfo.cFileName) - 3]), "gif") == 0 ||
strcmp( &(pNextInfo.cFileName[strlen(pNextInfo.cFileName) - 3]), "swf") == 0 )
{
continue;
} fileNum++; //file num plus memset(buffer, 0, sizeof(buffer));
sprintf(buffer, "%s\\%s", inputpath, pNextInfo.cFileName); readfd = fopen(buffer, "r");
if( readfd == NULL )
{
sprintf(ErrMess, "%s", "can not fopen file %s\\%s", inputpath, pNextInfo.cFileName);
printf(ErrMess);
WriteErrToOutputFlie(localpath, ErrMess);
} while(!feof(readfd))
{
if(fgetc(readfd) == '\n')
flieline++;
}
flieline++; //Last line fclose(readfd); fprintf(writefd, "\t%s", pNextInfo.cFileName);
fprintf(writefd, ":%d\n", flieline);
AllCodeLine += flieline;
}
flieline = 0; }
} int main(int argc, char *argv[])
{
int ret = 0;
char ErrMess[250] = {0};
char buffer[250] = {0};
FILE *writefd; memset(localpath, 0, sizeof(localpath));
if(argc != 2)
{
exit(1);
} strncpy_s(localpath, sizeof(localpath), argv[1], strlen(argv[1])); ret = CreteOutputFlie(localpath);
if(ret != 0)
{
sprintf(ErrMess, "%s", "main call CreteOutputFlie failed!");
printf(ErrMess);
WriteErrToOutputFlie(localpath, ErrMess);
} memset(buffer, 0, sizeof(buffer));
sprintf(buffer, "%s\\%s", localpath, "output.txt"); writefd = fopen(buffer, "w"); ret = File_Check_operation(localpath, localpath, writefd);
if(ret != 0)
{
sprintf(ErrMess, "%s", "main call File_Check_operation failed!");
printf(ErrMess);
WriteErrToOutputFlie(localpath, ErrMess);
} fprintf(writefd, "\n\n AllCodeLine is : %d", AllCodeLine); fclose(writefd); return 0;
}
代码行数统计(指定目录下所有文件的Line)的更多相关文章
- java代码行数统计工具类
package com.syl.demo.test; import java.io.*; /** * java代码行数统计工具类 * Created by 孙义朗 on 2017/11/17 0017 ...
- python实现指定目录下批量文件的单词计数:并发版本
在 文章 <python实现指定目录下批量文件的单词计数:串行版本>中, 总体思路是: A. 一次性获取指定目录下的所有符合条件的文件 -> B. 一次性获取所有文件的所有文件行 - ...
- socket实现两台FTP服务器指定目录下的文件转移(不依赖第三方jar包)
通过socket实现两台FTP服务器指定目录下的文件转移,其中包含了基础了ftp文件列表显示.上传和下载.这里仅供学习用,需掌握的点有socket.ftp命令.文件流读取转换等 完整代码如下: Ftp ...
- linux --> 删除指定目录下所有文件
删除指定目录下所有文件 代码样例: ///////////////////////////////////////////////////// //Name: DeleteFile //Purpose ...
- PHP 获取指定目录下所有文件(包含子目录)
PHP 获取指定目录下所有文件(包含子目录) //glob — 寻找与模式匹配的文件路径 $filter_dir = array('CVS', 'templates_c', 'log', 'img', ...
- iOS案例:读取指定目录下的文件列表
// // main.m // 读取指定目录下的文件列表 // // Created by Apple on 15/11/24. // Copyright © 2015年 Apple. All rig ...
- PHP 批量获取指定目录下的文件列表(递归,穿透所有子目录)
//调用 $dir = '/Users/xxx/www'; $exceptFolders = array('view','test'); $exceptFiles = array('BaseContr ...
- 文件名命工具类(将指定目录下的文件的type类型的文件,进行重命名,命名后的文件将去掉type)
import java.io.File; /** * <b>function:</b> 文件命名工具类 * @author hoojo * @createDate 2012-5 ...
- C# 获取指定目录下所有文件信息
/// <summary> /// 返回指定目录下所有文件信息 /// </summary> /// <param name="strDirectory&quo ...
- [转]C# 获取指定目录下所有文件信息、移动目录、拷贝目录
原文:http://blog.csdn.net/vchao13/article/details/6200255 1.获取指定目录下所有文件信息 /// <summary> /// 返回指定 ...
随机推荐
- 回顾——Dom节点类型
DOM 节点 在 HTML DOM 中,所有事物都是节点.DOM 是被视为节点树的 HTML. 根据 W3C 的 HTML DOM 标准,HTML 文档中的所有内容都是节点: 整个文档是一个文档节点 ...
- centos mininet安装-坑
https://blog.csdn.net/milesandnick/article/details/108017349?utm_medium=distribute.pc_relevant.none- ...
- IDEA激活 重置试用30天
转载于 https://www.cnblogs.com/renlywen/p/14216325.html jetbrains-agent已经停止,现在又出现了新的激活方式,重置试用时间,以下为操作步骤 ...
- transformers 之Trainer对应的数据加载
基础信息说明 本文以Seq2SeqTrainer作为实例,来讨论其模型训练时的数据加载方式 预训练模型:opus-mt-en-zh 数据集:本地数据集 任务:en-zh 机器翻译 数据加载 Train ...
- PGSQL新建临时表
初始化临时表,会话结束后自动删除 普通写法 CREATE TEMP TABLE tmp_student( id VARCHAR(10), name VARCHAR(3O), age INTEGER ) ...
- Markdwn学习
Markdwn学习 标题: 标题 二级标题 三级标题 几个标题有几个#(最多六级标题) 字体 Hell,World! 粗体两边加** Hello,World! 斜体两边加* Hello,World! ...
- java报错 SLF4J:Failed to load class "org.slf4j.impl.StaticLoggerBinder"
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artif ...
- CentOS7下MySQL数据的导入和导出
一.数据导入 (1)进入mysql [root@localhost mysql]# mysql -u root -p (2)转到对应数据库下 mysql> use zenith_star; (3 ...
- SqlServer基礎
REVERSE(欄位) 反轉 CHARINDEX(篩選字符,欄位,[start]) 例:CHARINDEX('/',ProImage,13) 從13位查詢/所在索引 SUBSTRING(欄位,star ...
- CSP202104-4校门外的树
`#include include include include include include include include include include include include us ...