movefile
Moves or renames a file or folder.
Category: Programming > Files and Folders
Syntax
movefile(source, destination)
Moves source to destination.
[status, message, messageid] = movefile(___)
Returns the outcome of the move.
Description
A move within one drive is a rename, so it is fast and keeps the content intact. If destination is a folder that exists, the item keeps its name inside it; otherwise the item takes the new name, which is how a file is renamed.
The source no longer exists after a successful move. To keep it, use copyfile.
Input arguments
source- File, folder or wildcard pattern.
destination- New name, or an existing folder to move into.
Output arguments
statustruewhen the move succeeded.message- Text describing the problem; empty on success.
messageid- Message identifier; empty on success.
Example
Renaming, then moving into a folder
writelines('v1', 'draft.txt');
mkdir archive
movefile('draft.txt', 'final.txt');
movefile('final.txt', 'archive');
[isfile('draft.txt'), isfile('final.txt'), isfile('archive/final.txt')]
Output
ans = 1×3 logical array
0 0 1