Why is there no boost::filesystem::move_file?

molholm picture molholm · Jun 30, 2010 · Viewed 15.1k times · Source

I'm using boost filesystem to replace windows C++ functions like CopyFile and MoveFile to get some kind of portability between windows and linux. I'm using copy_file but I have not been able to find anything that moves files like a 'move_file' function. Do boost have a move file function?

I would very much prefer to use boost, but alternative suggestions are welcome.

Answer

Philipp picture Philipp · Jun 30, 2010

It's called rename, see the manual. Like the corresponding OS functions, this might or might not work if the source and destination paths are on different file systems. If it doesn't work, use a copy operation followed by a delete operation.