copynewerfolder
SOURCE
,
DESTINATION

The copynewerfolder statement copies an entire folder full of files, but only copies newer files.


Parameters

This statement has two parameters:

source – Path of original folder

destination – Path of destination folder


Description

This statement copies an entire folder full of files. However, the files are only copied if they are newer than the old files..

This example copies the contents of the folder New Stuff into the folder Previous Stuff. Files in New Stuff that are older than the corresponding files in Previous Stuff are skipped (which can be a lot faster).

copynewerfolder "~/Documents/New Stuff/","~/Documents/Previous Stuff/"

Monitoring Progress

If the specified folder contains a lot of files that have changed, the copynewerfolder operation can take quite a while. If your procedure contains a copyProgress: label, the subroutine at that label will be called once for every file in the source folder (even if the file has not changed). The subroutine will have one parameter, a dictionary that contains information about the file and how it was handled (more about this dictionary in a moment).

Here is an example that displays the progress of the copynewerfolder operation in the tool bar banner. As the copy proceeds, the banner will fill up like a thermometer (see the setbannerprogressbar statement).

copynewerfolder "~/Documents/New Stuff/","~/Documents/Previous Stuff/"
return

copyProgress:
let progress = parameter(1)
let index = getdictionaryvalue(progress,"INDEX")
let count = getdictionaryvalue(progress,"COUNT")
setbannerprogressbar index/count
return

The dictionary passed to this subroutine contains four items:

In addition to being called after each file is copied, it is also called before the copy begins (with a COUNT of the number of files to be copied and an INDEX of 0). It is also called after the copy is finished, with a COUNT of 0 and INDEX of 0.

Warning: The code in the copyProgress: subroutine cannot access or modify any local variables in the main program. If you need a variable to be accessible to this subroutine, you must use a fileglobal, windowglobal or global variable.

Filtering the List of Files

The copynewerfolder statement normally copies all of the files in the folder. You can, however, set up a filter to restrict which files are copied. To do this, set up a subroutine inside the procedure that calls copynewerfolder with the label filterSourceFiles. Before it starts copying files, the copynewerfolder statement will call this subroutine, with the list of files it is about to copy as the parameter. The subroutine can modify the list, then pass it back to the copynewerfolder statement. Here is an example that will copy any PDF files in the New Stuff folder to the Previous Stuff folder.

copynewerfolder "~/Documents/New Stuff/","~/Documents/Previous Stuff/"
return

filterSourceFiles:
let sourcefiles = parameter(1)
sourcefiles = arraystrip(arrayfilter(sourcefiles,cr(),
    {?(import() endswith ".pdf",import(),"")}),cr())
setparameter 1,sourcefiles
return

Any non-PDF files in the New Stuff folder will be ignored.


See Also


History

VersionStatusNotes
10.2UpdatedNow can report progress back to the calling program, and can be programmed to filter the list of files to be copied. Also, this statement actually works now.
10.0No ChangeCarried over from Panorama 6.0.