Page 1 of 3

gzip batch

Posted: 15 Apr 2019 11:39
by geronimo1
Hello
i would to make a batch
to zip with gzip my (css, js, html) files which are into directories and subdirectories, i would also to conserve these files not zipped where they are
i would that
my zipped css files instead to be *.css.gz be *.csz
my zipped js files instead to be *.js.gz be *.jgz
my zipped html files instead to be *.html.gz be *.htz
is there someone who could help me for that
thanks a lot
http://gnuwin32.sourceforge.net/packages/gzip.htm

Re: gzip batch

Posted: 16 Apr 2019 02:01
by siberia-man
Very simple

Code: Select all

@echo off

setlocal

set "ext_o=.gz"

if /i "%~x1" == ".css"  set "ext_o=.csz"
if /i "%~x1" == ".js"   set "ext_o=.jgz"
if /i "%~x1" == ".html" set "ext_o=.htz"

gzip -c "%~dpnx1" > "%~dpn1%ext_o%"

Re: gzip batch

Posted: 16 Apr 2019 13:30
by geronimo1
A great thanks for your help siberia-man
i have installed gzip for windows with the setup
and by example

root/yourbatch.bat
root/index.html
root/js.js
root/file.css
root/firstdir/page1.html
root/firstdir/page2.html
root/2dir/page3.html
root/2dir/page4.html

nothing append

what is wrong?

Re: gzip batch

Posted: 16 Apr 2019 14:10
by siberia-man
geronimo1,

I am so sorry that I have made some rude mistakes. I updated my previous post and fixed them. Please try again.

Re: gzip batch

Posted: 17 Apr 2019 03:25
by geronimo1
still thank siberian-man
now i just got
maximun level for st local was reached
nothing else happend

Re: gzip batch

Posted: 17 Apr 2019 06:57
by siberia-man
I don't know and can't imagine what have you done. First of all, try to run the script with a single file check the result and go ahead with others.

Re: gzip batch

Posted: 17 Apr 2019 08:25
by geronimo1
hello with a single html file in the same directory than your batch i just got
.gz o octet

on a cmd command line -r mean recursive, -k mean keep file

C:>"C:\Program Files (x86)\GnuWin32\bin\gzip.exe" -r -k D:\Documents\mydirectory

i keep all the files and get all the files zipped in all directories but its with a cmd command line and all files are zipped not only css js and html

with -f mean force to copy under files if they exist i have an error i think its because my directory is in reading only, and i cannot uncheck it
C:>"C:\Program Files (x86)\GnuWin32\bin\gzip.exe" -r -k -f D:\Documents\mydirectory

Re: gzip batch

Posted: 17 Apr 2019 10:56
by geronimo1
maximun level for set local was reached

Re: gzip batch

Posted: 18 Apr 2019 02:20
by siberia-man
you do something not in right way. Please try with a single file and check your results.

Re: gzip batch

Posted: 18 Apr 2019 09:56
by geronimo1
hello
thanks again to try to help me

so i am with windows10

in the same directory only your batch + index.html



result: message without interruption: "Le niveau maximal de recursivité de set local a été atteint"
so i stop
then
your batch, index.html, -c.gz, .gz
(the two files -c.gz and .gz are 0 octets)

Re: gzip batch

Posted: 18 Apr 2019 10:22
by Squashman
No problems using the script on my end.

Directory listing

Code: Select all

C:\BatchFiles\GZIP>dir
 Volume in drive C is 15_10P
 Volume Serial Number is DE79-4A59

 Directory of C:\BatchFiles\GZIP

04/18/2019  11:20 AM    <DIR>          .
04/18/2019  11:20 AM    <DIR>          ..
04/18/2019  11:18 AM                34 file.css
04/18/2019  11:19 AM                53 foobar.js
04/18/2019  11:13 AM               207 gz.bat
04/18/2019  11:17 AM                18 index.html
               4 File(s)            312 bytes
               2 Dir(s)  64,868,696,064 bytes free
Run the batch file on each file.

Code: Select all

C:\BatchFiles\GZIP>gz.bat file.css

C:\BatchFiles\GZIP>gz.bat foobar.js

C:\BatchFiles\GZIP>gz.bat index.html
New Directory listing.

Code: Select all

C:\BatchFiles\GZIP>dir
 Volume in drive C is 15_10P
 Volume Serial Number is DE79-4A59

 Directory of C:\BatchFiles\GZIP

04/18/2019  11:21 AM    <DIR>          .
04/18/2019  11:21 AM    <DIR>          ..
04/18/2019  11:18 AM                34 file.css
04/18/2019  11:21 AM                59 file.csz
04/18/2019  11:21 AM                69 foobar.jgz
04/18/2019  11:19 AM                53 foobar.js
04/18/2019  11:13 AM               207 gz.bat
04/18/2019  11:17 AM                18 index.html
04/18/2019  11:21 AM                43 index.htz
               7 File(s)            483 bytes
               2 Dir(s)  64,868,564,992 bytes free

C:\BatchFiles\GZIP>

Re: gzip batch

Posted: 19 Apr 2019 00:51
by geronimo1

Code: Select all

Le volume dans le lecteur D n'a pas de nom.
 Le num‚ro de s‚rie du volume est AED5-0530

 R‚pertoire de D:\Documents\directory

19/04/2019  08:43                 0 -c.gz
19/04/2019  08:43                 0 .gz
16/04/2019  19:30            10˙167 file.css
19/04/2019  08:40               207 gzip.bat
19/04/2019  08:47                 0 txt
               5 fichier(s)           10˙374 octets
               0 R‚p(s)  384˙245˙366˙784 octets libres
---------------------------------------------------
 Le volume dans le lecteur D n'a pas de nom.
 Le num‚ro de s‚rie du volume est AED5-0530

 R‚pertoire de D:\Documents\directory

19/04/2019  08:49                 0 -c.gz
19/04/2019  08:49                 0 .gz
16/04/2019  19:30            10˙167 foobar.js
19/04/2019  08:40               207 gzip.bat
19/04/2019  08:49                 0 txt.txt
               5 fichier(s)           10˙374 octets
               0 R‚p(s)  384˙245˙366˙784 octets libres
---------------------------------------------------
 Le volume dans le lecteur D n'a pas de nom.
 Le num‚ro de s‚rie du volume est AED5-0530

 R‚pertoire de D:\Documents\directory

19/04/2019  08:40               207 gzip.bat
16/04/2019  19:30            10˙167 index.html
19/04/2019  08:50                 0 txt.txt
               3 fichier(s)           10˙374 octets
               0 R‚p(s)  384˙245˙366˙784 octets libres
------------------------------------------
the text.txt its because i use with cmd dir>text.txt to list directory
if i run your script fron c: its the same result

Re: gzip batch

Posted: 19 Apr 2019 04:33
by siberia-man
rename gzip.bat to gz.bat

Re: gzip batch

Posted: 19 Apr 2019 08:35
by Squashman
Would like to remind you that this is an English speaking forum and if you want help you need to translate everything to English.

Re: gzip batch

Posted: 19 Apr 2019 09:31
by aGerman
Come on Squashman. His explanation is in English. The French text is the quoted output of the DIR command. I suspect you don't need a translation for the header and footer :wink:

Steffen