view scripts/miscellaneous/unzip.m @ 6049:04c2ad6d1679

[project @ 2006-10-13 14:32:15 by jwe]
author jwe
date Fri, 13 Oct 2006 14:32:23 +0000
parents a18d85bdff31
children cd98c1e18d48
line wrap: on
line source

## Copyright (C) 2005 S�ren Hauberg
## 
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, write to the Free
## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.

## -*- texinfo -*-
## @deftypefn {Function File} unzip (@var{zipfile}, @var{dir})
## Unpack the ZIP archive @var{zipfile} to the directory @var{dir}.
## If @var{dir} is not specified, it defaults to the current directory.
## @seealso{tar, untar, gzip, gunzip, zip}
## @end deftypefn

## Author: S�ren Hauberg <hauberg@gmail.com>
## Adapted-By: jwe

function files = unzip (zipfile, dir)

  if (nargin == 1 || nargin == 2)

    if (nargin == 1)
      dir = ".";
    endif

    if (ischar (zipfile) && ischar (dir))

      [status, output] = system (sprintf ("unzip %s -d %s", zipfile, dir));

      if (status == 0)
	if (nargout > 0)
	  ## Create list of extracted files.  It blows that there seems
	  ## to be no way to get unzip to print a simple list of file
	  ## names.
	  files = strrep (output, "  inflating: ", "");
	  files = cellstr (split (files, "\n"));
	  files = files(2:end-1,:);
	  files = files';
	endif
      else
	error ("unzip: unzip exited with status = %d", status);
      endif
    endif

  else
    print_usage ("unzip");
  endif

endfunction