This is a routine about the file copy, I hope someone can use it, no need to explore it.
#include
Bool forceexist; const bufsize = 409600; // Basic unit is 400K
/ / -------------------------------------------------------------------------------------------- --------------------------- void __fastcall tform1 :: formcreate (TOBJECT * Sender) {Edit1-> Text = extractFilePath (paramstr (0) } // --------------------------------------------- ------------------------------ Void __fastcall tform1 :: butt * sender {ix (OpenDialog1-> Execute () ) {ANSISTRING FFILE = OpenDialog1-> FileName; Ansistring Tfile = Edit1-> Text ExtractFileName (ffile); if (copyfile (ffile, tfile) {
// Copy success ....} else {forceexist = false; deletefile (tfile);}}} // ------------------------- -------------------------------------------------- Bool TFORM1 :: CopyFile (ANSISTRING FROMFILE, ANSISTRING TOFILE) {BOOL RESULT (FALSE); File * fromf, * TOF; Int Numread, NumWritten; / * bufsiz is defined in stdio.h * / char buf [buff ";
Screen-> Cursor = CRHOURGLASS; TOF = FOPEN (Tofile.c_STR (), "WB"); fromf = fopen (fromfile.c_str (), "RB"); try {starttime = now (); struct stattbuf; / * get information about the file * / fstat (fileno (FromF), & statbuf); int ModVal = statbuf.st_size% bufsize; int MaxVal = statbuf.st_size / bufsize; if (ModVal) MaxVal ; ProgressBar1-> Max = MaxVal; float fsize = statbuf.st_size; TVARREC ARGS [2] = {0, fsize}; lblfilesize-> caption = format ("file size:%. * n bytes", args, 1); lblstarttime-> caption = "start time : " FormatorTime (" HH: NN: SS ", StartTime);
Forceexist = false; progressbar1-> position = 0; do {if (progressbar1-> position