From d3fd76cb12f9080cc49c7d9cb1bfab5b2d574aef Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Wed, 21 Sep 2016 17:19:40 +0200 Subject: Add position of file in archive to name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some archive disks are organized into “sections” and file order should be preserved in those cases. Add a simple commandline switch. --- extractAll.sh | 2 +- extractArchive.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/extractAll.sh b/extractAll.sh index 6139475..8b8649f 100755 --- a/extractAll.sh +++ b/extractAll.sh @@ -9,7 +9,7 @@ while read -r F; do destdir="${base}.extracted" echo "Extracting $F to $destdir" $root/linearizeDisk.py "$F" "$linear" - $root/extractArchive.py -o "$destdir" "$linear" + $root/extractArchive.py -n -o "$destdir" "$linear" pushd "$destdir" || continue for G in ./*; do echo "Converting $G to ${G}.txt" diff --git a/extractArchive.py b/extractArchive.py index 2e66879..f14a6b6 100755 --- a/extractArchive.py +++ b/extractArchive.py @@ -46,6 +46,8 @@ if __name__ == '__main__': parser.add_argument ('-f', '--force', help='Overwrite existing files', action='store_true') parser.add_argument ('-o', '--output', help='Output directory, defaults to archive name') parser.add_argument ('-v', '--verbose', help='Enable debugging messages', action='store_true') + parser.add_argument ('-n', '--number', help='Number files based on their position in the archive', + action='store_true') parser.add_argument ('file', help='Input file') args = parser.parse_args () @@ -69,6 +71,7 @@ if __name__ == '__main__': except FileExistsError: pass + i = 1 while True: # file header dataspace fileheader = FileHeaderDataspace (BytesIO (next (entries))) @@ -92,6 +95,8 @@ if __name__ == '__main__': logging.debug ('skipping quirks') e = e[pagesize:] + if args.number: + filename = '{:03d}_{}'.format (i, filename) outfile = os.path.join (args.output, filename) if os.path.exists (outfile) and not args.force: logging.info ('File {} exists, skipping'.format (outfile)) @@ -101,4 +106,5 @@ if __name__ == '__main__': outfd.write (e) stamp = mtime.timestamp () os.utime (outfile, (stamp, stamp)) + i += 1 -- cgit v1.2.3