File.copy

From MiniScript Wiki
Revision as of 03:14, 24 January 2021 by Mantic (talk | contribs) (Added some known limitations on error returning.)
Jump to navigation Jump to search

In Mini Micro and command-line MiniScript, the file.copy function copies a file on the system.

Arguments

Parameter Name Meaning
sourceFilePath absolute or relative path to the source file
targetFilePath absolute or relative path of the target file


Return Meaning
null File was copied successfully, or the source file was not found. (Use file.exists to check if the source file is present first.)
"Error: target file already exists" Target file already exists. file.copy won't override existing files.
"Error: target disk not found" targetFilePath cannot be navigated to, so no copy can be made.

Current limitations

  1. If you attempt to copy a file into a path, the file is not copied and no error is returned. EG: file.copy "myfile.txt", "/usr2"
  2. If you attempt to copy a directory, or to a directory, with no file names, it returns null with no error. EG: file.copy "/usr2", "/usr2/copy"

Example

This copies a file from the current working directory, to a directory just above it:

if file.exists("myfile.txt") then

  ret = file.copy("myfile.txt", "../mycopy.txt")

  if ret == null and file.exists("../mycopy.txt") then
    print "Copy successful!"
  else
    print "Copy failed: " + ret
  end if

end if