baXCopy copies multiple files from one folder to another folder, with wildcard matching, including sub-directories.


Windows and Macintosh


Result = baXCopy( SourceDir , DestDir , FileSpec , Overwrite, MakeDir )


String, string, string, string, integer.
SourceDir is the folder to copy from.
DestDir is the folder to copy to.
FileSpec determines what files are copied.
Overwrite determines how the copy is done. Can be:


always copies the file


copies the file if SourceFile is newer than DestFile


copies only if DestFile does not already exist

If MakeDir is true, any empty directories will be created.


Returns 0 if the file was copied successfully, otherwise one of these:

Invalid Source file name

Invalid Dest file name

Error reading the Source file

Error writing the Dest file

Couldn't create directory for Dest file

Dest file exists

Dest file is newer that Source file

No files matched the specified type


OK = baXCopy( "c:\data" , "d:\backup" , "*.dat " , "IfNewer" , true )

OK := baXCopy( "c:\\data" , "d:\\backup" , "*.*" , "Always" , false )


By default, this function will not overwrite an existing file if that file is marked as read-only. However, by adding "+" to the "Always" and "IfNewer" options (eg "Always+" or "IfNewer+"), the files will be overwritten if they are read-only.

The return value will not be 0 if any file is not copied. For example, if you specify

baXCopy( "c:\data" , "d:\backup" , "*.*" , "IfNewer" )

and any of the files in c:\data are newer than the ones in d:\backup, the return result will be 7 (Dest file is newer than Source). A result of 0 will be returned only if none of the files in c:\data is newer than d:\backup.

On Windows, the FileSpec argument follows normal DOS wildcard rules. Use "*.*" to copy all files.

On Macintosh, the FileSpec can be either a four character type code, eg “TEXT” or an extension, eg ".txt". You must include the . in the extension. Only one type or extension can be specified. Use an empty string or “*.*” to specify all files.

A return value of 6 (Dest file exists) can only be returned when Overwrite is "IfNotExist".

A return value of 7 (Dest file is newer than Source file) can only be returned when Overwrite is "IfNewer". The other return values can be returned for all Overwrite options.

The "IfNewer" option operates as follows: on Windows: if both files have internal version numbers, then these numbers are used for comparison, otherwise the dates of the two files are used for comparison. On Macintosh, only the file dates are used for comparison.

The new files will be set to archive and not read-only.


See also: