2 # A Perl5 sample script that uses Deark to try to recursively extract all the
3 # files from the files given on the command line.
4 # All extracted files will be written to the current directory, and will have
5 # names beginning with "output.".
6 # It is normal for error messages to be printed, when unsupported formats are
8 # This script is quick and dirty. Use at your own risk.
9 # Terms of use: Public domain
10 # By Jason Summers, 2018
13 my $deark_exe = "/usr/local/bin/deark";
19 my $code = join('.', @
$nlistref);
20 print "extracting from: $fn\n";
22 my @args = ($deark_exe, $fn, "-extrlist", "output.list",
23 "-a", "-o", "output.$code");
26 if($#$nlistref > 10) {
27 return; # emergency brake
30 # Make a list of the filenames that the previous command extracted.
32 open(my $extrlist, "<", "output.list") or die "Can't read output.list";
36 push @outputfns, $line;
39 unlink("output.list");
41 # Now we have the list. Call ourselves recursively.
43 foreach my $fn (@outputfns) {
44 push @
$nlistref, sprintf "%03d", $counter;
45 do_onefile
($nlistref, $fn);
52 my @nlist = (); # A stack used to construct output filenames
54 foreach my $fn (@ARGV) {
55 my $fn_sanitized = $fn;
56 if($fn_sanitized =~ /^(.*)[\/\\](.*)$/) { # Only use basename
61 $fn_sanitized =~ s/[\/\\:\*\?\"<>\|\c@-\c_]/_
/g
;
62 push @nlist, $fn_sanitized;
63 do_onefile
(\
@nlist, $fn);