⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 counter.cpp

📁 命令行方式的硬盘工具 可以在dos和nt下运行。 需要djgpp和vs7.0以上
💻 CPP
字号:
// Counter.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "winbase.h"
// testEnumAllfiles.cpp : 定义控制台应用程序的入口点。
//
typedef void (*P_SEARCHCALLBACK)(const string & fileFullName,  char * const pfileName) ;
BOOL FileNameFilter( char * const pfileName)
{
	char *p = pfileName;
	while (*p)
		p++;
	char *pEnd = p;
	while ( p > pfileName)
	{
		if( *p == '.')
			break;
		p--;
	}
	if ( p <= pfileName)
		return FALSE;
	p++;
	if (p>= pEnd)
		return FALSE;
	//cout << p <<endl;
	if (_stricmp("h", p) == 0)
		return TRUE;
	if (_stricmp("c", p) == 0)
		return TRUE;
	if (_stricmp("cpp", p) == 0)
		return TRUE;
	if (_stricmp("hpp", p) == 0)
		return TRUE;
	if (_stricmp("cc", p) == 0)
		return TRUE;
	if (_stricmp("txx", p) == 0)
		return TRUE;
	if (_stricmp("cxx", p) == 0)
		return TRUE;
	if (_stricmp("hxx", p) == 0)
		return TRUE;
	if (_stricmp("hh", p) == 0)
		return TRUE;
	return FALSE;
}

 int gLineTotal = 0;
void CallBackLogFilePosition(const string &fileFullName,  char * const pfileName)
{
	//cout<< fileFullName <<endl;
	if (!FileNameFilter(pfileName))
	{
		return;
	}
	ifstream fileIn;
	char * str = new char[1000000];
	fileIn.open(fileFullName.c_str());
	int line = 0;
	while(!fileIn.eof())
	{
		fileIn.getline(str,1000000-2);
		line++;
	}
	delete []str;
	cout << fileFullName << " 的行数为 " << dec << line << hex << endl;
	gLineTotal += line;

}

void CallBack(const string &fileFullName,  char * const pfileName)
{
	//cout<< fileFullName <<endl;
	if (!FileNameFilter(pfileName))
	{
		return;
	}
}

void Search(const string & pathName, P_SEARCHCALLBACK pCallBack)
{
	//char path[_MAX_PATH];
	string *path = new string(pathName);
	string *fullPath = new string(pathName);
	string *fullFileName = new string;
	*path += "\\*";
	*fullPath += "\\";
	//char bufFileAllPath[_MAX_PATH];
	//strcpy(path, pathName);
	//strcat(path,);
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind;
	hFind = FindFirstFileEx(path->c_str(), FindExInfoStandard, &FindFileData,
					FindExSearchNameMatch, NULL, 0 );

	if (hFind == INVALID_HANDLE_VALUE) 
	{
		cout<< "Invalid File Handle. GetLastError reports " << GetLastError () << endl;
		return ;
	} 
	else 
	{
		while(hFind != INVALID_HANDLE_VALUE)
		{
			*fullFileName = *fullPath + FindFileData.cFileName;
			DWORD attr = GetFileAttributes(fullFileName->c_str());
			if (attr & FILE_ATTRIBUTE_DIRECTORY)
			{
				if ( (strcmp(".", FindFileData.cFileName ) == 0) || ( strcmp("..", FindFileData.cFileName) == 0) )
					;
				else
				{
					Search(*fullFileName, pCallBack);
				}
			}
			else
			{
				pCallBack(*fullFileName, FindFileData.cFileName);
				//FILE_ATTRIBUTE_READONLY
				//FILE_ATTRIBUTE_SYSTEM
			}
			if (!FindNextFile(hFind, &FindFileData))
				break;
		}
		FindClose(hFind);
	}

	delete path;
	delete fullPath;
	delete fullFileName;
}

void Counter(const char *argv)
{
	gLineTotal = 0;
	Search(argv, CallBackLogFilePosition);
	cout << "总行数为 " << dec << gLineTotal << endl << hex;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -