Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copy and rename Fichs with WSH
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
00984296
Message ID:
00984315
Views:
23
CopyFile DOES support wilcards!
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsmthcopyfile.asp

>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform