
本文共 4406 字,大约阅读时间需要 14 分钟。
������������������������������Windows������������������������������������������������������������������������������������������
1. ������������
������������������MFC���������
���MFC������������������������������������������������CFileFind
���������������������������������������������
void FileCopyTo(CString source, CString destination, CString searchStr, BOOL cover /*= true*/){ CFileFind filefinder; CString strSearchPath = source + "//" + searchStr; BOOL bfind = filefinder.FindFile(strSearchPath); while (bfind) { bfind = filefinder.FindNextFile(); CString filename = filefinder.GetFileName(); CString sourcePath = source + "//" + filename; CString dispPath = destination + "//" + filename; CopyFile((LPCSTR)sourcePath, (LPCSTR)dispPath, cover); } filefinder.Close();}
���������������
CFileFind
������������������������������FindFile
���FindNextFile
���������������������������������- ���������������������������������������������������������������������
CopyFile
��������������������������� cover
���������������������������������������������
������������������C++���������
������C++������������������findfirst
���findnext
���������������������������������������������
#include#include #include #include #include void FileCopyTo(char *source, char *dis, char *searchChars, bool bcover /*= true*/){ struct _finddata_t ffblk; char path[256], SourcePath[256], DisPath[256]; sprintf(path, "%s//q_*", source); long done = _findfirst(path, &ffblk); int find = 0; while (find == 0) { if(strcmp(ffblk.name, "q_")) { sprintf(SourcePath, "%s//%s", source, ffblk.name); sprintf(DisPath, "%s//%s", dis, ffblk.name); CopyFile(SourcePath, DisPath, bcover); } find = _findnext(done, &ffblk); } _findclose(done);}
���������������
- ������
_finddata_t
��������������������������������� - ������
sprintf
���������������������CopyFile
��������������������������� find
������������������������������������������������������������
2. ������������
���������������������������������
���������������������������������������������������������������������������������������
bool DeleteDirectory(char* sDirName){ CFileFind tempFind; char sTempFileFind[200]; sprintf(sTempFileFind, "%s//*.*", sDirName); BOOL IsFinded = tempFind.FindFile(sTempFileFind); while (IsFinded) { IsFinded = tempFind.FindNextFile(); if (!tempFind.IsDots()) { char sFoundFileName[200]; strcpy(sFoundFileName, tempFind.GetFileName().GetBuffer(200)); if (tempFind.IsDirectory()) { char sTempDir[200]; sprintf(sTempDir, "%s//%s", sDirName, sFoundFileName); DeleteDirectory(sTempDir); } else { char sTempFileName[200]; sprintf(sTempFileName, "%s//%s", sDirName, sFoundFileName); DeleteFile(sTempFileName); } } } tempFind.Close(); if (!RemoveDirectory(sDirName)) { return FALSE; } return TRUE;}
���������������
- ������
CFileFind
��������������������������������������������� - ���������������������������������
DeleteDirectory
��������������� - ���������������������������������
DeleteFile
���������������������
������������������������������
���������������������������������������������������������������������������������������������������������������
int main(){ system("md d://aa//zhao "); // ������������������ system("del d://aa//zhao "); // ������������������������������������}
���������������
- ���oose���������
system
������������������������������������ "md d://aa//zhao "
������������������������������������������"del d://aa//zhao "
������������������������������������������
������������
FileCopyTo
������������cover
���������������TRUE
������������������������������������������<
���������������������������������������������������������������������Windows������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
