gzip batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
geronimo1
Posts: 15
Joined: 15 Apr 2019 11:31
Location: france
Contact:

gzip batch

#1 Post by geronimo1 » 15 Apr 2019 11:39

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

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: gzip batch

#2 Post by siberia-man » 16 Apr 2019 02:01

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%"
Last edited by siberia-man on 16 Apr 2019 14:08, edited 2 times in total.

geronimo1
Posts: 15
Joined: 15 Apr 2019 11:31
Location: france
Contact:

Re: gzip batch

#3 Post by geronimo1 » 16 Apr 2019 13:30

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?

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: gzip batch

#4 Post by siberia-man » 16 Apr 2019 14:10

geronimo1,

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

geronimo1
Posts: 15
Joined: 15 Apr 2019 11:31
Location: france
Contact:

Re: gzip batch

#5 Post by geronimo1 » 17 Apr 2019 03:25

still thank siberian-man
now i just got
maximun level for st local was reached
nothing else happend

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: gzip batch

#6 Post by siberia-man » 17 Apr 2019 06:57

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.

geronimo1
Posts: 15
Joined: 15 Apr 2019 11:31
Location: france
Contact:

Re: gzip batch

#7 Post by geronimo1 » 17 Apr 2019 08:25

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

geronimo1
Posts: 15
Joined: 15 Apr 2019 11:31
Location: france
Contact:

Re: gzip batch

#8 Post by geronimo1 » 17 Apr 2019 10:56

maximun level for set local was reached

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: gzip batch

#9 Post by siberia-man » 18 Apr 2019 02:20

you do something not in right way. Please try with a single file and check your results.

geronimo1
Posts: 15
Joined: 15 Apr 2019 11:31
Location: france
Contact:

Re: gzip batch

#10 Post by geronimo1 » 18 Apr 2019 09:56

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)

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: gzip batch

#11 Post by Squashman » 18 Apr 2019 10:22

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>

geronimo1
Posts: 15
Joined: 15 Apr 2019 11:31
Location: france
Contact:

Re: gzip batch

#12 Post by geronimo1 » 19 Apr 2019 00:51

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

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: gzip batch

#13 Post by siberia-man » 19 Apr 2019 04:33

rename gzip.bat to gz.bat

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: gzip batch

#14 Post by Squashman » 19 Apr 2019 08:35

Would like to remind you that this is an English speaking forum and if you want help you need to translate everything to English.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: gzip batch

#15 Post by aGerman » 19 Apr 2019 09:31

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

Post Reply