copyfolder
SOURCE
,
DESTINATION

The copyfolder statement copies an entire folder full of files (and subfolders, if any).


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 (and subfolders, if any). If the destination folder does not exist it will be created. If the destination folder does already exist it is not replaced, but files and folders from the source folder will be copied to it.

This example copies the contents of the folder New Stuff into the folder Previous Stuff.

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

Monitoring Progress

If the specified folder contains a lot of files, the copyfolder 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 that is copied. The subroutine will have one parameter, a dictionary that contains information about the file that was just copied (more about this dictionary in a moment).

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

copyfolder "~/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 an 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 copyfolder 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 copyfolder with the label filterSourceFiles. Before it starts copying files, the copyfolder 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 copyfolder statement. Here is an example that will copy any PDF files in the New Stuff folder to the Previous Stuff folder.

copyfolder "~/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.
10.0No ChangeCarried over from Panorama 6.0.