1. copy a file
/////////////////////////////////
// Copy an MFC File
/////////////////////////////////
Void filecopyto (cstring source, cstring destination, cstring searchstr, bool cover = true)
{
Cstring strsourcepath = source;
Cstring strdespath = destination;
Cstring strfilename = searchstr;
Cfilefind filefinder;
Cstring strsearchpath = strsourcepath + "//" + strfilename;
Cstring filename;
Bool bfind = filefinder. findfile (strsearchpath );
Cstring sourcepath, dispath;
While (bfind)
{
Bfind = filefinder. findnextfile ();
Filename = filefinder. getfilename ();
Sourcepath = strsourcepath + "//" + filename;
Dispath = strdespath + "//" + filename;
Copyfile (lpcstr) sourcepath, (lpcstr) dispath, cover );
}
Filefinder. Close ();
}
/////////////////////////////////
// Copy a C ++ File
/////////////////////////////////
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
# Include <Io. h>
# Include <windows. h>
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 );
}
2. delete a file
// Delete the folder directory (not empty)
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;
}
-------------------------------------------------------------
Method 2 (directly call the command ):
# Include <stdlib. h>
# Include <stdio. h>
Int main ()
{
System ("md d: // AA // Zhao"); // create a folder
System ("del D: // AA // Zhao"); // delete all files in this folder
}
Article Source: http://www.diybl.com/course/3_program/vc/vc_js/2008426/111574.html