Board index » cppbuilder » Copy whole folder (only files which has been changed)

Copy whole folder (only files which has been changed)


2004-09-02 07:45:51 PM
cppbuilder24
Hi,
in my application i like to copy a whole folder to another place. i use
these functions:
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);
return back;
}
void __fastcall TForm1::dir_create(AnsiString source, AnsiString target)
{
source = IncludeTrailingBackslash(source);
target = IncludeTrailingBackslash(target);
TSearchRec sr;
if( FindFirst(source + "*.*", faAnyFile, sr) == 0 )
{
do
{
if({*word*59} == true)
return;
if( (sr.Name == ".") || (sr.Name == "..") )
continue;
AnsiString CurrentSource = source + sr.Name;
AnsiString CurrentTarget = target + sr.Name;
if( sr.Attr & faDirectory )
{
if( !DirectoryExists(CurrentTarget) )
{
CreateDir(CurrentTarget);
}
dir_create(CurrentSource, CurrentTarget);
}
else
{
if (RBOverwrite->Checked == false && FileExists(CurrentTarget))
{
}
else
{
// copy
CopyTheFile(CurrentSource, CurrentTarget);
}
}
}
while( FindNext(sr) == 0 );
FindClose(sr);
}
}
Problem is, that i can only switch if i like to overwrite a file or not.
this i not good, i only like to copy the files which has been changed. there
should be any solution with the a flag. please help me.
greetings tommy
 
 

Re:Copy whole folder (only files which has been changed)

"Tommy" < XXXX@XXXXX.COM >wrote in message
Quote
i only like to copy the files which has been changed.
Before calling CopyTheFile(), you should be looking at the timestamps on
each file and see if they match or not. For the source file, the TSearchRec
already contains the timestamps for the file. For the target file, you will
have to retreive the timestamps manually. You can use FindFirst()
specifying the full filename to get a second TSearchRec, or you can open the
file and then use GetFileTime() from the Win32 API.
Gambit
 

Re:Copy whole folder (only files which has been changed)

Hi,
waht is with the possibility to work with SetFileAttribute and
GetFileAttribute and work with the Archieve Flag.
Would this also be a good ay?
tommy
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote

"Tommy" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>i only like to copy the files which has been changed.

Before calling CopyTheFile(), you should be looking at the timestamps on
each file and see if they match or not. For the source file, the
TSearchRec
already contains the timestamps for the file. For the target file, you
will
have to retreive the timestamps manually. You can use FindFirst()
specifying the full filename to get a second TSearchRec, or you can open
the
file and then use GetFileTime() from the Win32 API.


Gambit


 

{smallsort}