]> git.lyx.org Git - lyx.git/blob - src/support/rename.cpp
add FileName::renameTo() method.
[lyx.git] / src / support / rename.cpp
1 /**
2  * \file rename.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/lyxlib.h"
14 #include "support/FileName.h"
15
16 #include <cstdio>
17
18
19 namespace lyx {
20 namespace support {
21
22 bool rename(FileName const & from, FileName const & to)
23 {
24         if (::rename(from.toFilesystemEncoding().c_str(),
25                         to.toFilesystemEncoding().c_str()) != -1) 
26                 return true;
27         if (!copy(from, to))
28                 return false;
29         from.removeFile();
30         return true;
31 }
32
33
34 } // namespace support
35 } // namespace lyx