7017
|
1 ## Copyright (C) 2003, 2004, 2005, 2006, 2007 John W. Eaton |
4264
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
4264
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
4264
|
18 |
|
19 ## -*- texinfo -*- |
4350
|
20 ## @deftypefn {Function File} {[@var{dir}, @var{name}, @var{ext}, @var{ver}] =} fileparts (@var{filename}) |
4264
|
21 ## Return the directory, name, extension, and version components of |
|
22 ## @var{filename}. |
5835
|
23 ## @seealso{fullfile} |
4264
|
24 ## @end deftypefn |
|
25 |
|
26 function [directory, name, extension, version] = fileparts (filename) |
|
27 |
|
28 if (nargin == 1) |
5443
|
29 if (ischar (filename)) |
4264
|
30 ds = rindex (filename, filesep); |
|
31 es = rindex (filename, "."); |
5073
|
32 ## These can be the same if they are both 0 (no dir or ext). |
|
33 if (es <= ds) |
4683
|
34 es = length(filename)+1; |
|
35 endif |
4264
|
36 directory = filename(1:ds-1); |
|
37 name = filename(ds+1:es-1); |
5073
|
38 if (es > 0) |
|
39 extension = filename(es:end); |
|
40 else |
|
41 extension = ""; |
|
42 endif |
4264
|
43 version = ""; |
|
44 else |
4424
|
45 error ("fileparts: expecting filename argument to be a string"); |
4264
|
46 endif |
|
47 else |
6046
|
48 print_usage (); |
4264
|
49 endif |
|
50 |
|
51 endfunction |