5807
|
1 ## Copyright (C) 2005 S�ren Hauberg |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
|
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 ## -*- texinfo -*- |
|
18 ## @deftypefn {Function File} unzip (@var{filename}) |
|
19 ## @deftypefnx {Function File} unzip (@var{filename}, @var{outputdir}) |
|
20 ## Unpacks the archive @var{filename} using the unzip program. |
|
21 ## The resulting files are placed in the directory @var{outputdir}, |
|
22 ## which defaults to the current directory. |
|
23 ## @end deftypefn |
|
24 |
|
25 ## Author: S�ren Hauberg <hauberg at gmail dot com> |
|
26 |
|
27 function files = unzip(filename, outputdir) |
|
28 if (nargin == 0) |
|
29 print_usage("unzip"); |
|
30 elseif (nargin == 1) |
|
31 outputdir = "."; |
|
32 endif |
|
33 |
|
34 ## Make sure filename and outputdir are strings |
|
35 if (!ischar(filename) || !ischar(outputdir)) |
|
36 error("All arguments must be strings.\n"); |
|
37 endif |
|
38 |
|
39 ## Should we append ".zip" to filename? |
|
40 if (length(filename) <= 4 || !strcmp(filename(end-3:end), ".zip")) |
|
41 filename = sprintf("%s.zip", filename); |
|
42 endif |
|
43 |
|
44 ## Call unzip |
|
45 [output, status] = system(["unzip -o " filename " -d " outputdir]); |
|
46 if (status != 0) |
|
47 error("unzip returned the following error: %s\n", output); |
|
48 endif |
|
49 |
|
50 ## Create list of extracted files. This might depend on which version |
|
51 ## unzip that it used, although I do not know this for sure. |
|
52 if (nargout) |
|
53 files = strrep(output, " inflating: ", ""); |
|
54 files = split(files, "\n"); |
|
55 # remove first and last line from the output |
|
56 files = files(2:end-1, :); |
|
57 endif |
|
58 endfunction |
|
59 |