Merge remote-tracking branch 'origin/master' into windows
[scilab.git] / scilab / modules / fileio / src / c / movefile.c
1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009 - DIGITEO - Allan CORNET
4 *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13 *
14 */
15 /*--------------------------------------------------------------------------*/
16 #include "movefile.h"
17 #include "deleteafile.h"
18 #include "removedir.h"
19 #include "copyfile.h"
20 #include "createdirectory.h"
21 #include "isdir.h"
22 /*--------------------------------------------------------------------------*/
23 int MoveFileFunction(char *DestinationFilename, char *SourceFilename)
24 {
25     int ierr = 0;
26     ierr = CopyFileFunction(DestinationFilename, SourceFilename);
27     if (ierr == 0)
28     {
29         if (deleteafile(SourceFilename))
30         {
31             return 0;
32         }
33         else
34         {
35             return 1;
36         }
37     }
38     return 0;
39 }
40 /*--------------------------------------------------------------------------*/
41 int MoveDirectoryFunction(char *DestinationDirectory, char *SourceDirectory)
42 {
43     int ierr = 0;
44
45     if ( !isdir(DestinationDirectory)  )
46     {
47         createdirectory(DestinationDirectory);
48     }
49
50     ierr = CopyDirectoryFunction(DestinationDirectory, SourceDirectory);
51     if (ierr == 0)
52     {
53         if (removedir(SourceDirectory))
54         {
55             return 0;
56         }
57         else
58         {
59             return 1;
60         }
61     }
62     return 0;
63
64 }
65 /*--------------------------------------------------------------------------*/