84198e788a059942b726bc30a33f0d2a68a0eab6
[scilab.git] / scilab / modules / fileio / macros / mkdir.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2007 - INRIA - Allan CORNET
3 //
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10 function [status,msg]=mkdir(varargin)
11         // mkdir Make a directory
12         //------------------------------------------------------------------------
13         
14         lhs        = argn(1);
15         rhs        = argn(2);
16         
17         DirName    = '';
18         NewDirName = '';
19         status     = 0 ;
20         msg        = '';
21         
22         select rhs
23
24         case 0
25                 error('Number of parameters incorrect.');
26                 break
27         
28         case 1
29                 NewDirName   = varargin(1);
30                 NewDirName   = stripblanks(NewDirName,%T);
31                 if is_absolute_path(NewDirName) then
32                         NewDirectory = NewDirName;
33                 else
34                         NewDirectory = fullfile(pwd(),NewDirName);
35                 end
36                 break
37                 
38         case 2
39                 DirName      = varargin(1);
40                 NewDirName   = varargin(2);
41                 NewDirName   = stripblanks(NewDirName,%T);
42                 DirName      = stripblanks(DirName,%T);
43                 NewDirectory = fullfile(DirName,NewDirName);
44                 break
45                 
46         else
47                 error('Number of parameters incorrect.');
48         end
49         
50         if (fileinfo(NewDirectory)==[]) then
51                 // The directory does not exist
52                 status = 1;
53         else
54                 // The directory or file exists
55                 if (isdir(NewDirectory)) then
56                         // it is a directory
57                         status = 2;
58                 else
59                         // it is a file
60                         status = -2;
61                 end
62         end
63         
64         select status
65
66         case 0
67                 break
68                 
69         case 1
70                 status = createdir(NewDirectory);
71                 if (~status) then
72                         msg    = "Error(s) Impossible to create directory "+NewDirectory+".";
73                         status = 0;
74                 else
75                         msg    = '';
76                         status = 1;
77                 end
78                 break
79                 
80         case 2
81                 msg = "This directory already exists in "+DirName+".";
82                 break
83
84         case -2
85                 msg = "A file with the same name already exists in "+DirName+".";
86                 break
87         
88         else
89                 msg = "Error(s) Impossible to create directory "+NewDirectory+".";
90         end
91         
92 endfunction