Difference between revisions of "File.copy"

From MiniScript Wiki
Jump to navigation Jump to search
(First draft of file.copy.)
 
m (Added some known limitations on error returning.)
Line 24: Line 24:
 
|}
 
|}
  
 
+
== Current limitations ==
 +
# If you attempt to copy a file into a path, the file is not copied and no error is returned. EG: <c>file.copy "myfile.txt", "/usr2"</c>
 +
# If you attempt to copy a directory, or to a directory, with no file names, it returns ''null'' with no error. EG: <c>file.copy "/usr2", "/usr2/copy"</c>
  
 
== Example ==
 
== Example ==
Line 31: Line 33:
  
 
<ms>if file.exists("myfile.txt") then
 
<ms>if file.exists("myfile.txt") then
 +
 
   ret = file.copy("myfile.txt", "../mycopy.txt")
 
   ret = file.copy("myfile.txt", "../mycopy.txt")
   if ret == null then
+
 
 +
   if ret == null and file.exists("../mycopy.txt") then
 
     print "Copy successful!"
 
     print "Copy successful!"
 
   else
 
   else
 
     print "Copy failed: " + ret
 
     print "Copy failed: " + ret
 
   end if
 
   end if
 +
 
end if</ms>
 
end if</ms>
  
 
[[Category:Mini Micro]]
 
[[Category:Mini Micro]]
 
[[Category:Command-Line MiniScript]]
 
[[Category:Command-Line MiniScript]]

Revision as of 03:14, 24 January 2021

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