Subject Re: Comparing Modification Date Between the same file name
From Mervyn Bick <invalid@invalid.invalid>
Date Fri, 24 Jun 2016 18:07:22 +0200
Newsgroups dbase.getting-started
Attachment(s) synchronise_foders.prg

On 24/06/2016 09:41, kent wrote:
> Hi ,
>
> is there any code for this?
> The scenario is this :
>
> I have 2 different folders "FOLDER A" and "FOLDER B" ,
> Folder A is the active Folder Database , Folder B is the back up Folder.
> Now I want to compare (a loop) all the content of both folders base on their modification date.
>
> Conditions are as follows:
>
> A.  If a file name from The Folder A has different modification (more advance in date) date as with Folder B , system will copy the file from Folder A overwriting File to the folder B.
> B. if a file name from Folder A has the same modification date as compared to folder B , system will do nothing.
> C. if a file name from folder A is not present to the folder B , system will copy file to Folder B.
>
> is this possible?

Of course. :-)

The little program attached should get you started.  It has been tested
but before you try it make sure you have a full backup elsewhere "just
in case".

It only copies sourcecode.  It does not copy data, compiled source or
the backup files that the dBASE editor creates.  You can, of course
change this if you want to.

Adir() fills an array with details of files in a folder.   See the OLH
for a description.  The array is arranged in rows of 5 columns.

Pay special attention to the different ways the two arrays are accessed.
  The source array is accessed row by row which is why the for...next
loop sets the limit to aSource/5 and the values in the columns are
[n,1],[n,3] and [n,4]

scan() returns the element number in the Backup arrray not the row
number.  To extract the date and time the values are, therefore,
retrieved by element number eg nRow (column 1), nRow+2 (column 3) and
nRow+3 (column 4)


Mervyn.






clear
cSource = 'd:\examples\plus10\'
cBackup = 'd:\examples\plus10\Backup\'
set safety off
aSource = new array()
adir(aSource,cSource+'*.*')
aBackup = new array()
adir(aBackup ,cBackup+'*.*')

for n = 1 to aSource.size/5
   cSname = trim(aSource[n,1])
   if upper(substr(cSname,len(cSname),1)) <> 'O' ;
         and not upper(cSname) = 'BACKUP' ;
         and not '.MDX'$upper(cSname) ;
         and not '.DBF'$upper(cSname) ;
         and not '.DBT'$upper(cSname)
      cSdate = aSource[n,3]
      cStime = aSource[n,4]
      nRow = aBackup.scan(cSname)
      cFromFile = cSource+cSname
      cToFile = cBackup+cSname      
      if nRow = 0 //Not in Backup
         copy file '&cFromFile' to '&cToFile'
      else  
         cBname = aBackup[nRow]
         cBdate = aBackup[nRow+2]
         cBtime = aBackup[nRow+3]
         if cSdate < cBdate
            copy file '&cFrom' to '&cBackup'        
         elseif cSdate = cBdate ;
               and cStime < cBtime
            copy file '&cFrom' to '&cBackup'
         endif            
      endif  
   endif
next
set safety on
? 'Done'