File.move

From MiniScript Wiki
Revision as of 04:10, 17 July 2021 by JoeStrout (talk | contribs) (Created page with "The <c>file.move</c> method moves or renames a file on disk to a different name/path on the same disk. === Arguments === {| class="wikitable" |- ! Parameter Name !! Defa...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The file.move method moves or renames a file on disk to a different name/path on the same disk.

Arguments

Parameter Name Default Value Meaning
oldPath "" file name, partial path, or absolute path to existing file or directory
newPath "" file name, partial path, or absolute path to new location

If either parameter given a file name or partial path, it will be interpreted relative to the current working directory (see file.curdir).

If newPath specifies an existing directory, MiniScript will attempt to move the file into that directory (keeping the original file name). Otherwise, the file will be moved/renamed to the given new path.

Result

If the file was successfully moved/renamed, this method returns true (1). Otherwise, it returns false (0). This can happen if the old file does not exist, if some file already exists at the new path, or if some other low-level issue occurs (for example, the file is locked).

Example

The following attempts to rename a file called "foo.txt" to "bar.txt" in the current directory.

file.move "foo.txt", "bar.txt"