FileTools[Compressed] - Maple Programming Help

Home : Support : Online Help : Programming : Input and Output : File Manipulation : FileTools : FileTools/Compressed/Extract

FileTools[Compressed]

 Extract
 uncompress a file and write it out to a new file

 Calling Sequence Extract(sourcefilename, destfilename, opts)

Parameters

 sourcefilename - string destfilename - string opts - options as specified below

Options

 • overwrite : (optional) truefalse ; overwrite file if it exists on disk
 • includepath : (optional) truefalse ; include directory structure on extract

Description

 • Extract is an all-in-one command to open a file, uncompress it, and write the uncompressed data out to a new file.
 • If sourcefilename is a zip archive and destfilename is a path, then all members of the zip archive will be extracted to the given path. To extract a single file from a zip archive, specify sourcefilename using the syntax "specificmember" in "filename.zip".
 • If the option overwrite=true is given, then an error will not be raised if the file to be extracted already exists on disk. The default is false.
 • If the option, includepath=true is given, then the subdirectory structure of the given zip file will be preserved in the extracted files.  If this option is set to false, then the subdirectory structure will be discarded during extraction.  It is undetermined which file will be written if there are multiple files with the same base name. The default is includepath=true.

Examples

Construct a file in zip format and extract from it.

 > $\mathrm{zipfile}≔\mathrm{FileTools}[\mathrm{TemporaryFilename}]\left(\mathrm{cat}\left(\mathrm{FileTools}[\mathrm{TemporaryDirectory}]\left(\right),\mathrm{kernelopts}\left(\mathrm{dirsep}\right),"GZtest-"\right),".zip"\right)$
 ${\mathrm{zipfile}}{:=}{"/mnt/tmpfs/mpldoc_slot3/mpldoc2/GZtest-yYoYxV9R.zip"}$ (1)
 > FileTools[Compressed][WriteFile]("first" in zipfile, "one");
 ${3}$ (2)
 > FileTools[Compressed][WriteFile]("second" in zipfile, Array(1..50, 0, datatype=integer[1]));
 ${50}$ (3)
 > $\mathrm{FileTools}[\mathrm{Compressed}][\mathrm{Contents}]\left(\mathrm{zipfile}\right)$
 $\left[{"first"}{,}{"second"}\right]$ (4)

Add directory structure to the zip file and extract it.

 > $\mathrm{dir}≔\mathrm{FileTools}[\mathrm{TemporaryFilename}]\left(\mathrm{cat}\left(\mathrm{FileTools}[\mathrm{TemporaryDirectory}]\left(\right),\mathrm{kernelopts}\left(\mathrm{dirsep}\right),"ztest-"\right)\right)$
 ${\mathrm{dir}}{:=}{"/mnt/tmpfs/mpldoc_slot3/mpldoc2/ztest-bx70dpPu"}$ (5)
 > $\mathrm{FileTools}:-\mathrm{MakeDirectory}\left(\mathrm{dir}\right)$
 > $\mathrm{FileTools}[\mathrm{Compressed}][\mathrm{Extract}]\left(\mathrm{zipfile},\mathrm{dir}\right)$
 > $\mathrm{FileTools}:-\mathrm{ListDirectory}\left(\mathrm{dir}\right)$
 $\left[{"second"}{,}{"first"}\right]$ (6)
 > $\mathrm{FileTools}:-\mathrm{Text}:-\mathrm{ReadFile}\left(\mathrm{cat}\left(\mathrm{dir},"/first"\right)\right)$
 ${"one"}$ (7)
 > $\mathrm{FileTools}:-\mathrm{Binary}:-\mathrm{ReadFile}\left(\mathrm{cat}\left(\mathrm{dir},"/second"\right)\right)$
 $\left[\begin{array}{c}{\mathrm{1 .. 50}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{{\mathrm{integer}}}_{{1}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (8)
 > $\mathrm{FileTools}[\mathrm{Remove}]\left(\mathrm{cat}\left(\mathrm{dir},"/first"\right)\right)$
 > $\mathrm{FileTools}[\mathrm{Remove}]\left(\mathrm{cat}\left(\mathrm{dir},"/second"\right)\right)$
 > $\mathrm{FileTools}:-\mathrm{ListDirectory}\left(\mathrm{dir}\right)$
 $\left[{}\right]$ (9)
 > FileTools[Compressed][Extract]("first" in zipfile,dir);
 > $\mathrm{FileTools}:-\mathrm{ListDirectory}\left(\mathrm{dir}\right)$
 $\left[{"first"}\right]$ (10)
 > $\mathrm{FileTools}:-\mathrm{Text}:-\mathrm{ReadFile}\left(\mathrm{cat}\left(\mathrm{dir},"/first"\right)\right)$
 ${"one"}$ (11)
 > $\mathrm{FileTools}[\mathrm{Remove}]\left(\mathrm{cat}\left(\mathrm{dir},"/first"\right)\right)$
 > $\mathrm{FileTools}[\mathrm{RemoveDirectory}]\left(\mathrm{dir},'\mathrm{forceremove}'\right)$
 > $\mathrm{FileTools}[\mathrm{Remove}]\left(\mathrm{zipfile}\right)$

Compatibility

 • The FileTools[Compressed][Extract] command was introduced in Maple 18.
 • The  and  options were introduced in Maple 18.