19

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.

molholm
  • 1,852
  • 3
  • 22
  • 27

2 Answers2

36

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.

alfC
  • 10,293
  • 4
  • 42
  • 88
Philipp
  • 43,805
  • 12
  • 78
  • 104
  • 4
    I confess that reading the manual and then in turn reading the ISO C page referred to by the manual, I don't see anything explicitly stating that the destination can be a file in another directory in order to move the file from one directory to another. A careful reading implies that this is possible, but I think the boost documentation would be much more useful and more clear if it stated this possibility explicitly. Boost documentation ticket: https://svn.boost.org/trac/boost/ticket/9643 – legalize Feb 07 '14 at 14:58
  • 2
    move (as mv under Linux) works across different filesystem while rename does not. – trax Mar 19 '18 at 15:02
-6
void add_time(ptime& gen_time, int seconds) {
    boost::posix_time::millisec_posix_time_system_config::time_duration_type time_elapse(0, 0, seconds);
    //time_elapse = p2 - p1;
    gen_time = gen_time + time_elapse;
}
Taryn
  • 224,125
  • 52
  • 341
  • 389