Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Copy and rename Fichs with WSH
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Database:
Visual FoxPro
Divers
Thread ID:
00984296
Message ID:
00984309
Vues:
20
AFAIK CopyFile doesn't support wildcards. But You can build Your own function:
FUNCTION CopyAndRename(cSourceFiles, cTargetFiles)

   LOCAL nFiles, nfCycle, nCopyType, cFileExt
   LOCAL cFilePath, cSourcePath, cSource, cTarget
   ** IF cTargetFiles is only Path just copy files
   ** IF cTargetFiles is path+ wildcard copy & rename
   nCopyType = 0
   cFileExt  = JUSTEXT(cTargetFiles)
   DO CASE
      CASE "*" $ cFileExt .OR. "?" $ cFileExt
           nCopyType = 1
      CASE .NOT. EMPTY(cFileExt)
           nCopyType = 2
   ENDCASE
   cFilePath = JUSTPATH(cTargetFiles)
   TRY
      md (cFilePath)
   CATCH
   ENDTRY

   nFiles  = ADIR(aFiles, cSourceFiles)
   IF nFiles == 0
      RETURN -1 && No files match the criteria
   ENDIF 

   IF nFiles > 1 .AND. nCopyType == 2 .AND. .NOT. "*" $ JUSTFNAME(cTargetFiles)
      RETURN -2 && Can't copy several files with one name
   ENDIF
   cSourcePath = ADDBS(JUSTPATH(cSourceFiles))

   FOR nfCycle = 1 TO nFiles
       cSource = cSourcePath  + aFiles[nfCycle ,1]
       cTarget = cTargetFiles + IIF(nCopyType==0,aFiles[nfCycle ,1],"")
       COPY FILE (cSource) TO (cTarget)
   NEXT

RETURN 0
Test it. I did some tests but they not enough.
This function works with
CopyAndRename("c:\eltest20\data\*.dbf", "c:\mmm\data\*.dbf")
CopyAndRename("c:\eltest20\data\*.dbf", "c:\mmm\data\aa*.dbf")
CopyAndRename("c:\eltest20\data\*.dbf", "c:\mmm\data\")

but You must do some additional tests
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform