How to move a file

This topic describes how to move a single file to a different directory without renaming it.

You can move a single file to a different directory without renaming it, using RFs::Rename().


// Move file.txt from dir1 to dir2
_LIT(KFileSource,"\\dir1\\file.txt");
_LIT(KFileTarget,"\\dir2\\file.txt");
User::LeaveIfError(fsSession.Rename(KFileTarget,KFileSource));

Notes

  • RFs::Replace() can also be used to move a file. The difference between the two functions is that Rename() will return an error if a file with the new name already exists in the target directory whereas Replace() will overwrite it. Another way to move files is to use CFileMan::Move(). This may be used to move multiple files.