annotate scripts/miscellaneous/unzip.m @ 5807:29c4fb42b210

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