Subject Re: Comparing Modification Date Between the same file name
From Mervyn Bick <invalid@invalid.invalid>
Date Wed, 29 Jun 2016 11:17:29 +0200
Newsgroups dbase.getting-started

On 29/06/2016 05:52, kent wrote:
> HI MRVYN,
>
> HOW ABOUT IF IT has sub folders inside it?
> or even a sub folders inside a sub folders?


Mm.  I did say "The little program attached should get you started."
How you take it further is up to you.

The "quick and dirty" way is to copy and paste the entire block of code
for as many folders you need to process.  Change the cSource and cBackup
values to suit for each block.

A more elegant way is to create an array holding the names of the
folders you want to back up.

Wrap the code in a for... next loop

for n = 1 to arrayname.size
    cSource = arrayname[n]
    cBackup = arrayname[n]+'backup\'
    // this assumes that the folder name in the array includes a final \
    ........ the rest of the code block
next

If you add more folders later it is up to you to ensure that the back up
folders exist before you run the program.

The next step is to build the array of folders and sub-folders in the
program.  Filerecurser.cc in the dUFLP makes this easy.

******* Start of example code ********
    set procedure to :dUFLP:FileRecurser.cc
    x = new FileRecurser( "d:\examples\plus10" )
    aFolders1  = new array() // this array will contain ALL the file names.
    x.processFile := {|d,f|; aFolders1.add(d + f)}
    x.search()
    aFolders = new array() //We only want folder names so build a new
array for them
    if aFolders1.size > 0
       cFolder = substr(aFolders1[1],1,rat('\',aFolders1[1]))
       aFolders = new array()
       aFolders.add(cFolder)
       for n = 2 to aFolders1.size  // the first folder has already been
added
          if cFolder <> substr(aFolders1[n],1,rat('\',aFolders1[n]))
              cFolder = substr(aFolders1[n],1,rat('\',aFolders1[n]))
              aFolders.add(cFolder)
           endif
       next
    endif
****** End of example code ******


To view the list

    for n = 1 to aFolders.size
       ? aFolders[n]
    next

You can use the list of sub-folders as it stands if you are sure that
the backup folders exist.

If you regularly add folders that need to be backed up you can write
code to either check to see if a backup folder exists and, if not,
create it it or you can simply try and create each one every time you
run the program.  In this case you need to wrap the mkDir command in a
try...catch...endtry construct as trying to create a folder that exists
will give an error.  The try...catch...endtry allows dBASE to simply
carry on if the folder exists.

The final step is to adapt the program so that it can accept a
parameters.  This will enable you to pass a source folder and a backup
folder to the program.  You will then be able to easily backup more than
one folder.

Just how fancy you make this program is up to you.

Mervyn.