oFileIo.xcopy('c:\MyFolder','*.dbf;*.cdx;*.fpt',; 'c:\MyBackup_'+ttoc(datetime(),1), .t.)To copy all dbf,cdx and fpt files from c:\MyBackUp' and its subfolders to a new (or existing) directory. Part of class code with CopyFile in it :
* DLL declarations Declare integer SetFileAttributes in Win32API string @ lpFileName, integer dwFileAttributes Declare integer GetFileAttributes in Win32API string @ lpFileName Declare short CopyFile in win32API string @ lpExistingFileName, string @ lpNewFileName, short bFailIfExists Declare short MoveFile in win32API string @ lpExistingFileName, string @ lpNewFileName declare short DeleteFile in win32API string @ lpFileName DECLARE integer GetLastError in win32API * DLL declarations * ::xcopy method Lparameters tcSourcePath, tcMask, tcTargetPath, tlRecursive, tlNoOverwrite Local lnFailIfExists, lnErrors, lcTargetName, lcSourceFile, lcTargetFile, llDone This.CurrentAlias = Alias() lnFailIfExists = Iif(tlNoOverwrite,1,0) lnErrors = 0 With This .SetProps(tcSourcePath, tcMask, tcTargetPath, tlRecursive) If .FileMask == '' && Append source last folder to target path then copy .Target = Addbs(.Target + Justfname(Left(.SourcePath,Len(.SourcePath)-1))) .FileMask = '*.*' Endif .ShowUI('copy') .makedir(.Target) .GetTree('_cpy2_') * Create directory tree first .CreateDirectories('_cpy2_') Select _cpy2_ .InitUI(Reccount('_cpy2_'),'Copying...') Scan For !Bittest(fAttr,4) lcTargetName = Addbs(Trim(Stuff(filepath,1,Len(.SourcePath),.Target))) lcSourceFile = Trim(filepath)+Trim(FileName) lcTargetFile = lcTargetName+Trim(FileName) llDone = ._Execute(1, lcSourceFile, lcTargetFile , lnFailIfExists) lnErrors = lnErrors + Iif(llDone,0,1) .UpdateUI(lcSourceFile, lcTargetFile) Endscan .DestroyUI() Endwith This.RestoreAlias() Return lnErrors * ::_Execute Lparameters tnOperation, tcSource, tcTarget, tnFailIfExists Local ix, llSuccess For ix=1 To 3 && 3 trials Do Case Case tnOperation = 1 && Copy llSuccess = ( CopyFile(tcSource, tcTarget, tnFailIfExists) # 0 ) If !llSuccess And GetLastError() = 80 And tnFailIfExists = 0 && File exists If ( DeleteFile(tcTarget) # 0 ) && Delete first llSuccess = ( CopyFile(tcSource, tcTarget, tnFailIfExists) # 0 ) && Retry Endif Endif Case tnOperation = 2 && Move llSuccess = ( MoveFile(tcSource, tcTarget) # 0 ) Case tnOperation = 3 && Delete llSuccess = ( DeleteFile(tcSource) # 0 ) Endcase If llSuccess Return .T. Endif Endfor Return .F.Cetin