Discussion:
zip files in separate files according to part of filename
(too old to reply)
Ammammata
2023-04-07 16:42:28 UTC
Permalink
Hello

I have 72k html files whose name is in the format yyyymmddxxxxxx.html

I'd like to pack them in ZIP/7Z files, divided per year (first 4
characters) or year and month (1-6 filename)

Any help is appreciated, thank you
--
/-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\
-=- -=- -=- -=- -=- -=- -=- -=- - -=-
........... [ al lavoro ] ...........
Herbert Kleebauer
2023-04-08 07:33:03 UTC
Permalink
Post by Ammammata
Hello
I have 72k html files whose name is in the format yyyymmddxxxxxx.html
I'd like to pack them in ZIP/7Z files, divided per year (first 4
characters) or year and month (1-6 filename)
Any help is appreciated, thank you
That depends on the zip program you use. But if it is a
one time job and only for a few number of years (the
number of files doesn't matter) it is maybe easier to
do it manually. For example if the years are from
2010 - 2023:

Use explorer to create an empty zip file with the name
2023.zip then at the cmd prompt enter:

for /l %i in (2010,1,2022) do copy 2023.zip %i.zip

which creates all the (empty) zip files.

Then in explorer (sorted by name) select all files
2010*.html and move them all at once into the zip file
2010.zip And then repeat this with the other years.
Herbert Kleebauer
2023-04-08 08:27:51 UTC
Permalink
Post by Herbert Kleebauer
Post by Ammammata
Hello
I have 72k html files whose name is in the format yyyymmddxxxxxx.html
I'd like to pack them in ZIP/7Z files, divided per year (first 4
characters) or year and month (1-6 filename)
Any help is appreciated, thank you
For example if the years are from
Thanks for your question! This way I have learned, that
the Windows tar program can als create zip files. At the
cmd prompt type:

for /l %i in (2010,1,2023) do tar -a -cf %i.zip %i*.html

Or double the % if used in a batch file:

for /l %%i in (2020,1,2023) do tar -a -cf %%i.zip %%i*.html
JJ
2023-04-08 12:36:20 UTC
Permalink
Post by Herbert Kleebauer
Thanks for your question! This way I have learned, that
the Windows tar program can als create zip files. At the
for /l %i in (2010,1,2023) do tar -a -cf %i.zip %i*.html
for /l %%i in (2020,1,2023) do tar -a -cf %%i.zip %%i*.html
TAR only support creating TAR archive format. It doesn't support creating
other archive format including ZIP.

What you're doing is simply creating TAR archive with incorrectly named file
extension. As a ZIP file.

"ZIP" file created like this won't be able to be extracted using ZIP-only
tool such as InfoZIP.
Herbert Kleebauer
2023-04-08 12:43:17 UTC
Permalink
Post by JJ
Post by Herbert Kleebauer
Thanks for your question! This way I have learned, that
the Windows tar program can als create zip files. At the
for /l %i in (2010,1,2023) do tar -a -cf %i.zip %i*.html
for /l %%i in (2020,1,2023) do tar -a -cf %%i.zip %%i*.html
TAR only support creating TAR archive format. It doesn't support creating
other archive format including ZIP.
What you're doing is simply creating TAR archive with incorrectly named file
extension. As a ZIP file.
"ZIP" file created like this won't be able to be extracted using ZIP-only
tool such as InfoZIP.
I had the same opinion until a few hours ago.

https://superuser.com/questions/1659653/what-is-the-meaning-of-a-option-in-tar-exe-command

-a, --auto-compress
(c mode only) Use the archive suffix to decide a set of the
format and the compressions. As a simple example,
tar -a -cf archive.tgz source.c source.h
creates a new archive with restricted pax format and gzip
compression,
tar -a -cf archive.tar.bz2.uu source.c source.h
creates a new archive with restricted pax format and bzip2
compression and uuencode compression,
tar -a -cf archive.zip source.c source.h
creates a new archive with zip format,
tar -a -jcf archive.tgz source.c source.h
ignores the "-j" option, and creates a new archive with
restricted pax format and gzip compression,
tar -a -jcf archive.xxx source.c source.h
if it is unknown suffix or no suffix, creates a new archive with
restricted pax format and bzip2 compression.
JJ
2023-04-09 01:10:51 UTC
Permalink
Post by Herbert Kleebauer
I had the same opinion until a few hours ago.
https://superuser.com/questions/1659653/what-is-the-meaning-of-a-option-in-tar-exe-command
That won't work right out of the box (of TAR package).

It'll require a separate archiver tool for the appropriate archive format
such as BZIP2, GZIP, ZIP, etc. - which isn't guaranteed to always exist
along with TAR in every system.

FYI, TAR won't show any error or warning message if the needed archiver tool
is missing. So, the created file would be e.g. ZIP named TAR archive.
Herbert Kleebauer
2023-04-09 07:25:42 UTC
Permalink
Post by JJ
Post by Herbert Kleebauer
I had the same opinion until a few hours ago.
https://superuser.com/questions/1659653/what-is-the-meaning-of-a-option-in-tar-exe-command
That won't work right out of the box (of TAR package).
It'll require a separate archiver tool for the appropriate archive format
such as BZIP2, GZIP, ZIP, etc. - which isn't guaranteed to always exist
along with TAR in every system.
Who cares about "every system"? This is alt.msdos.batch and
the batch code posted here also doesn't work with "every system".

The tar.exe provided with Win10 (and I suppose also the Win11 version)
can generate zip compressed files without installing any additional
software. I think this are a good news.

And I even suppose, that all the code for BZIP2, GZIP, ZIP, etc. is
part of tar.exe (in the current version), so no "separate archiver
tool" is needed. But I didn't test it, because all I need is to
generate zip files and that works.
Ammammata
2023-04-11 07:49:12 UTC
Permalink
Post by Herbert Kleebauer
for /l %i in (2010,1,2022) do copy 2023.zip %i.zip
well, I didn't know this "from--step--to" format, thank you

FOR /L %variable IN (start,step,end) DO command [command-parameters]

The set is a sequence of numbers from start to end, by step amount.
So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
generate the sequence (5 4 3 2 1)

It will work fine, I'll test it later, this evening
--
/-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\
-=- -=- -=- -=- -=- -=- -=- -=- - -=-
........... [ al lavoro ] ...........
Ammammata
2023-04-22 08:49:30 UTC
Permalink
Il giorno Tue 11 Apr 2023 09:49:12a, *Ammammata* ha inviato su
Post by Ammammata
I'll test it later, this evening
later than scheduled, but I did it... and was ok :)
--
/-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\
-=- -=- -=- -=- -=- -=- -=- -=- - -=-
........... [ al lavoro ] ...........
Loading...