Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Deleting a Folder
Message
De
06/04/2004 04:59:32
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00892135
Message ID:
00892547
Vues:
14
>Ok. Can you give example of copy with WinApi?
>Thanks
>Steve

It's basically :
CopyFile(m.tcSourceFile, m.tcTargetFile, m.tnFailIfExists)

I've created a FileOperations.vcx which takes care of copy/move/delete of extended path/extensions selection with/or w/o a user progbar interface. ie:
I can make a call like this :
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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform