Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copy Only Files That Have Changed to Duplicate Drive
Message
 
To
09/08/2007 09:42:56
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01246997
Message ID:
01247096
Views:
21
>Has anyone already written anything which copies a directory structure but only copies those files that have changed? I have a utility that does that, but I want to do something specific to VFP files. For example, if the file is part of a form and either the .sct or .scx have changed, I want to copy both the .sct and .scx. The same for reports and classes, et al.
>
>I have another workstation with a mapped drive letter that I need to have a copy of a directory and its subdirectories on. I don't want to copy every file in the entire directory though if not necessary.
>
>I could write something, but I think it has already been done...
CopyDiff([c:\Project folder],[d:\back up folder])



FUNCTION CopyDiff(lcSourceFolder, lcTargetFolder)
         LOCAL laFiles[1], lnFor, lnFiles, lbCopyFile
         LOCAL laFilesTrg[1], lnAscan, lnFilesTrg, lcNewExt
         LOCAL lcFileSource, lcFileTarget
         lcSourceFolder = ADDBS(lcSourceFolder)
         lcTargetFolder = ADDBS(lcTargetFolder)

         lnFiles = ADIR(laFiles, lcSourceFolder+[*.*])
                   ADIR(laFilesTrg,lcTargetFolder)
         FOR lnFor = 1 TO lnFiles
             IF NOT LEFT(laFiles[lnFor,1],2) == [.]
                IF [D] $ UPPER(laFiles[lnFor,5])
                   *** Folder copy it
                   TRY
                     md (lcTargetFolder+laFiles[lnFor,1])
                   CATCH
                   ENDTRY
                   CopyDiff(lcSourceFolder+laFiles[lnFor,1], lcTargetFolder+laFiles[lnFor,1])
                ELSE
                   lbCopyFile = .t.
                   lcFileSource = lcSourceFolder+laFiles[lnFor,1]
                   lcFileTarget = lcTargetFolder+laFiles[lnFor,1]
                   IF lnFilesTrg # 0
                      *** If lnFilesTrg  == 0 then there is 
                      *** NO files in that folder, so you don't have to care about EXT, all files will be copied there
 
                      lnAscan = ASCAN(laFilesTrg,laFiles[lnFor,1],1,-1,1,1,11)
                      IF lnAscan > 0
                         IF laFilesTrg[lnAscan,3] # laFiles[lnFor,3] OR;
                            laFilesTrg[lnAscan,4] # laFiles[lnFor,4]
                            IF JUSTEXT(laFiles[lnFor,1]) $ [VCX VCT SCX SCT FRX FRT DBF DBT]
                               lcNewExt = LEFT(JUSTEXT(laFiles[lnFor,1]),2)+[*]
                               lcFileSource = FORCEEXT(lcSourceFolder+laFiles[lnFor,1],lcNewExt)
                               lcFileTarget = FORCEEXT(lcTargetFolder+laFiles[lnFor,1],lcNewExt)
                            ENDIF
                         ELSE
                            lbCopyFile = .f.
                         ENDIF
                      ENDIF
                   ENDIF
                   IF lbCopyFile
                      COPY FILE (lcFileSource) TO (lcFileTarget)
                   ENDIF
                ENDIF
             ENDIF
         ENDFOR
not tested at all. I wrote it directly here :-)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform