資源簡介
只有1個.cpp文件。但可以遍歷磁盤,并將結果輸出到文件。功能很強大,絕對好用。
使用方法:
運行程序:
首先輸入要遍歷的目錄:
比如:
C:\ 或者 C:\Windows
然后,輸入你要存儲這些記錄的.txt文件,比如
D:\result.txt (需要提前建立好)
然后就等待程序結果吧。
當然,如果有自己的需要可以自己進行修改。

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
using?namespace?std;
#ifdef?_UNICODE
#define?TCHAR?wchar
#else
#define?TCHAR?char
#endif
//file?stream?
fstream?fStream;
//count?the?total?file?number?in?the?directory?
static?int?fileCount=0;
void?file_scan(char*?root)
{
char?filePath[MAX_PATH];
????char?tmpPath[MAX_PATH];
char?filePath_Name[MAX_PATH];
????
memset(filePath0MAX_PATH);
????memset(tmpPath0MAX_PATH);
memset(filePath_Name0MAX_PATH);
????WIN32_FIND_DATA?fd;
????memset(&fd0sizeof(WIN32_FIND_DATA));
????HANDLE?hSearch;
????strcpy(filePath?root);
????BOOL?bSearchFinished?=?FALSE;
????if(?filePath[strlen(filePath)?-1]?!=?‘\\‘?)
????{
strcat(filePath?“\\“);
}
????strcat(filePath?“*“);
????hSearch?=?FindFirstFile(filePath?&fd);
????
//?the?file?is?a?dir??its?name?should?not?be?‘.‘‘..‘?and?not?begin?with?‘$‘
????if(?(fd.dwFileAttributes?&?FILE_ATTRIBUTE_DIRECTORY)
&&?(fd.cFileName[0]!=‘.‘)?&&(fd.cFileName[0]!=‘$‘)?)??????
????{
strcpy(tmpPath?root);
strcat(tmpPath?fd.cFileName);
//recursion
file_scan(tmpPath);
????}
//?normal?file
????else?if(?strcmp(fd.cFileName?“.“)?&&?strcmp(fd.cFileName?“..“)&&?fd.cFileName[0]!=‘$‘)
????{
strcpy(filePath_Nameroot);
strcat(filePath_Name“\\“);
strcat(filePath_Namefd.cFileName);
struct?_stat?fileinfo;??
_stat(filePath_Name?&fileinfo);??
char?buf[20];
memset(buf020);
_ui64toa(fileinfo.st_sizebuf+210);
//插入兩個空格
buf[0]=0x20;
buf[1]=0x20;
fStream.write(filePath_Namestrlen(filePath_Name));
fStream.write(bufstrlen(buf));
fStream.write(“\r\n“2);
memset(filePath_Name0MAX_PATH);
cout<
++fileCount;
????}
????while(?!bSearchFinished?)
????{
if(?FindNextFile(hSearch?&fd)?)
{
if(?(fd.dwFileAttributes?&?FILE_ATTRIBUTE_DIRECTORY)
&&?strcmp(fd.cFileName?“.“)?&&?strcmp(fd.cFileName?“..“)?)??????
{
strcpy(tmpPath?root);
memset(tmpPath+strlen(tmpPath)0MAX_PATH-strlen(tmpPath));
if(tmpPath[strlen(tmpPath)]!=‘\\‘)
{
tmpPath[strlen(tmpPath)]=‘\\‘;
tmpPath[strlen(tmpPath)+1]=‘\0‘;
}
strcat(tmpPath?fd.cFileName);
file_scan(tmpPath);
}
else?if(strcmp(fd.cFileName?“.“)?&&?strcmp(fd.cFileName?“..“)&&?fd.cFileName[0]!=‘$‘)
{
strcpy(filePath_Nameroot);
strcat(filePath_Name“\\“);
strcat(filePath_Namefd.cFileName);
struct?_stat?fileinfo;??
_stat(filePath_Name?&fileinfo);??
char?buf[20];
memset(buf020);
_i64toa(fileinfo.st_sizebuf+210);
//插入兩個空格
buf[0]=0x20;
buf[1]=0x20;
fStream.write(filePath_Namestrlen(filePath_Name));
fStream.write(bufstrlen(buf));
fStream.write(“
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2011-11-09?09:33??File_Scan\
?????目錄???????????0??2011-10-12?19:43??File_Scan\Debug\
?????文件??????304459??2011-10-12?19:43??File_Scan\Debug\FileScan.obj
?????文件??????573508??2011-10-12?19:43??File_Scan\Debug\File_Scan.exe
?????文件??????830640??2011-10-12?19:43??File_Scan\Debug\File_Scan.ilk
?????文件?????1997432??2011-10-12?09:43??File_Scan\Debug\File_Scan.pch
?????文件?????1164288??2011-10-12?19:43??File_Scan\Debug\File_Scan.pdb
?????文件??????205824??2011-10-12?19:43??File_Scan\Debug\vc60.idb
?????文件??????143360??2011-10-12?19:43??File_Scan\Debug\vc60.pdb
?????文件????????4042??2011-10-12?19:43??File_Scan\FileScan.cpp
?????文件????????4319??2011-10-12?10:15??File_Scan\File_Scan.dsp
?????文件?????????543??2011-10-12?09:42??File_Scan\File_Scan.dsw
?????文件???????41984??2011-11-09?09:33??File_Scan\File_Scan.ncb
?????文件???????49664??2011-11-09?09:33??File_Scan\File_Scan.opt
?????文件????????1311??2011-10-12?19:43??File_Scan\File_Scan.plg
?????目錄???????????0??2011-10-13?10:30??File_Scan\for?develop\
?????文件??????573508??2011-10-12?19:43??File_Scan\for?develop\File_Scan.exe
?????文件????????4957??2011-10-13?09:09??File_Scan\for?develop\game.txt
?????文件??????184964??2011-10-13?08:28??File_Scan\for?develop\knowledge.txt
?????文件??????298110??2011-10-13?08:29??File_Scan\for?develop\movie.txt
?????文件???????74923??2011-10-13?08:30??File_Scan\for?develop\music.txt
?????文件???????57664??2011-10-13?10:30??File_Scan\for?develop\tools.txt
?????文件???????57963??2011-10-13?09:24??File_Scan\for?develop\tools.txt.bak
?????文件????????8931??2011-10-13?08:31??File_Scan\for?develop\video.txt
?????文件?????????570??2011-06-07?14:03??File_Scan\for?develop\welcome.txt
- 上一篇:C++圖像處理幾何校正可運行工程
- 下一篇:C++FAQ中文版
評論
共有 條評論