function
Library: File system utilities (OMVFS)
Import : omvfs.xmd |
export external function copy value string source-path on value directory source-dir optional to value string target-path in value directory target-dir optional
Argument definitions
You can use vfs.copy
to copy a file or directory to a new location. vfs.copy
will not overwrite a file or directory that already exists.
import "omvfs.xmd" prefixed by vfs. process vfs.copy "../version1" to "/oldversion"
There are two ways to use vfs.copy. The first is a straight copy and the second is copy and rename.
In straight copy mode, the source parameter names the file or directory to be copied and the target parameter names the destination to which that file or directory will be copied. That location must exist, and the specifed file or directory is created in that location using its existing name. Thus the following code copies the file test.txt from directory foo to directory bar, creating a copy of test.txt in that directory:
import "omvfs.xmd" prefixed by vfs. process vfs.copy "c:\foo\test.txt" to "c:\bar\"
In copy and rename mode, the source parameter names the file or directory to be moved and the target parameter names the destination to which that file or directory will be copied, and the new name it will be given at that destination. Thus the following code copies the file test.txt from directory foo to directory bar, creating a file named experiment.txt in that directory with the same contents as test.txt:
import "omvfs.xmd" prefixed by vfs. process vfs.copy "c:\foo\test.txt" to "c:\bar\experiment.txt"
The difference between straight copy mode and copy and rename mode is determined by examining the target parameter. When copying files, the interpretation of this parameter is unambiguous. However, when copying directories, the distinction between straight copy and copy and rename can depend on the current state of the file system. Consider the following program:
import "omvfs.xmd" prefixed by vfs. process vfs.copy "c:\temp\bar" to "c:\foo\baz"
If the directory c:\foo\baz exists, the function operates in straight copy mode, creating a directory with the name bar inside the baz directory and copying the contents of c:\temp\bar into that directory. This creates a new directory named c:\foo\baz\bar.
However, if the directory c:\foo\baz does not exist, but the directory c:\foo does exist, the function operates in copy and rename mode, creating a directory named baz in c:\foo, and copying the contents of c:\temp\bar into that directory. This creates a new directory named c:\foo\baz.
This means that if the program above were executed three times in succession, and assuming that initially c:\foo exists and c:\foo\bar does not, it would have three different outcomes.
For this reason, you should check the status of the copy destination before using vfs.copy
to copy directories.
The following exceptions may occur: