Board index » cppbuilder » copy files and directorys on recursiv way - directory folder problem
Tommy
![]() CBuilder Developer |
copy files and directorys on recursiv way - directory folder problem2004-07-02 07:07:34 AM cppbuilder16 Hi, in my application i use a recursiv copy routine, to copy all files and directorys from a to b. my problem is that my copy functions seems to try to copy folders and write error messages. my code works fine! every file will be copy! nothing is missing. but i always get errors. For exmaple: ----------------------------- C:\\Datenbank\c64 could not copy: Access denied C:\\Games\c64 to C:\\Datenbank\c64 did not copy ----------------------------- C:\\Datenbank\c64 is a directory and not a file. why is my application try to copy this? i do not understand. here are my recursive function and my copy function: void __fastcall TForm1::dir_create(AnsiString source, AnsiString target) { TSearchRec sr; source = IncludeTrailingBackslash(source); AnsiString wildcard = source + "*"; target = IncludeTrailingBackslash(target); // Attribute int iAttributes = faDirectory; if (FindFirst(wildcard,iAttributes, sr) == 0) { do { // Directory if( (sr.Attr & faDirectory) && (sr.Name != ".") && (sr.Name != "..") ) { if (!DirectoryExists(target + sr.Name)) { CreateDir(target + sr.Name); } LStatus2->Caption = target + sr.Name; Application->ProcessMessages(); dir_create(source + sr.Name, target + sr.Name); } // File if( (sr.Attr & faAnyFile) && (sr.Name != ".") && (sr.Name != "..") ) { LStatus2->Caption = target + sr.Name; Application->ProcessMessages(); CopyTheFile(source + sr.Name,target + sr.Name); } } while(FindNext(sr) == 0); FindClose(sr); } FindClose(sr); } //-------------------------------------------------------------------------- - bool __fastcall TForm1::CopyTheFile(String source, String target) { BOOL bCancelled = FALSE; bool back = CopyFileEx(source.c_str(), target.c_str(),MyCopyProgressRoutine, this, &bCancelled, COPY_FILE_RESTARTABLE); // Bei Fehlermeldung anzeigen if (back == false) { DWORD er = GetLastError(); char er_str[200]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,er,0,(char*)&er_str,200,NULL); MProtokoll->Lines->Add("-----------------------------"); MProtokoll->Lines->Add(target + " could not copy: " + er_str); MProtokoll->Lines->Add(source + " to " + target + " did not copy"); MProtokoll->Lines->Add("-----------------------------"); // ShowMessage(er_str); } return back; } //-------------------------------------------------------------------------- - Might there be any problems when some files are write protected and i try to overwrite them? any ideas for my problem? tommy |