Source: Nanshan CFileFind Find files/folders The simplest source of implementation
Instant Messenger software EnthusiastNanshanToday to write a CFileFind find files/folders The simplest implementation of the source code
CFileFind Finder;
CString wildcard (FILEPATHCP);
Wildcard + = _t ("\\*.*");
int rd = rand ()% 10;
if (rd > 0 && Rd <= 5)//select subfolders randomly under the current folder
{
BOOL bworking = Finder. FindFile (wildcard);
while (bworking)
{
bworking = Finder. FindNextFile ();
if (finder. Isdirectory () &&!finder. Isdots ())
{
if (rand ()% > 7)
{
FILEPATHCP = Finder. GetFilePath ();
Break
}
}
}
}
else if (rd > 5 && Rd <= 7)//Create subfolders
{
CString pathtemp;
Pathtemp.format ("%s\\dir%d", Filepathcp, dircount++);
CreateDirectory (Pathtemp, NULL);
FILEPATHCP = pathtemp;
}
else//Back to previous level folder
{
BOOL bworking = Finder. FindFile (wildcard);
while (bworking)
{
if (Filepathcp.right (strlen (SELF->FILEPATHG)) = = SELF->FILEPATHG)
Break
bworking = Finder. FindNextFile ();
if (!finder. Isdots ())
{
FILEPATHCP = Finder. Getroot ();
Break
}
}
}
and rename folders, files, or rewrite files under the appropriate folders
rd = rand ()%100;
if (rd <= 50)//Rename folder or file
{
BOOL bworking = Finder. FindFile (filepathcp+_t ("\\*.*"));
while (bworking)
{
bworking = Finder. FindNextFile ();
if (finder. Isdots ())
Continue
if (finder. Isdirectory ())
{
if (finder. GetFilePath (). Find (_t ("Modified")) < 0)
{
OutputDebugString (_t ("Rename dir\n"));
CString NewFileName;
Newfilename.format (_t ("%s\\modified%d"), finder. Getroot (), count++);
BOOL fsuccess = MoveFileEx (finder. GetFilePath (), NewFileName,
movefile_replace_existing);
FILEPATHCP = NewFileName;
Break
}
Else
Continue
}
else if (rand ()% 5 = 1 && finder. GetFilePath (). Find (_t ("modifyed")) < 0)
{
OutputDebugString (_t ("Rename file\n"));
CString NewFileName;
Newfilename.format (_t ("%smodifyed.txt"), finder. GetFilePath (). Left (finder. GetFilePath (). GetLength ()-4));
Rename (finder. GetFilePath (), newfilename);
}
}
}
else if (RD < 52)//delete folder or file
{
if (Filepathcp.right (strlen (self->filepathm))!= self->filepathm && rand ()% 58 = 1)
{
BOOL bworking = Finder. FindFile (filepathcp+_t ("\\*.*"));
while (bworking)
{
bworking = Finder. FindNextFile ();
if (rand ()% = = 1 && finder. Isdirectory () &&!finder. Isdots () && Finder. GetFilePath (). Right (strlen (self->filepathm))!= self->filepathm)
{
OutputDebugString (_t ("delete dir\n"));
Self->deletedirectory (finder. GetFilePath ());
FILEPATHCP = Finder. Getroot ();
Break
}
}
}
Else
{
OutputDebugString (_t ("delete file\n"));
BOOL bworking = Finder. FindFile (wildcard);
while (bworking)
{
bworking = Finder. FindNextFile ();
if (!finder. Isdirectory () &&!finder. Isdots () && rand ()% 10 = 0)
{
DeleteFile (finder. GetFilePath ());
FILEPATHCP = Finder. Getroot ();
Break
}
}
}
Copy Code