How to move files in Qt?
Solution 1
Sure, QDir::rename() following the old Unix / POSIX tradition of calling this rename.
Which makes sense if you think of a file with its complete path: the underlying inodes just get assigned a different path/file label.
Solution 2
You would use QDir::rename() but be beware of the special cases when rename() can fail:
On most file systems,
rename()fails only ifoldNamedoes not exist, ifnewNameandoldNameare not on the same partition or if a file with the new name already exists. However, there are also other reasons whyrename()can fail. For example, on at least one file systemrename()fails ifnewNamepoints to an open file.
sashoalm
Updated on March 25, 2020Comments
-
sashoalm almost 3 yearsIs there a cross-platform function in Qt that is equivalent to the MoveFile function in Windows and the mv command in Linux?