Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch file for compressing code

225 views
Skip to first unread message

Harry Potter

unread,
Aug 26, 2021, 4:08:14 PM8/26/21
to
Hi! I have a batch file I've been using for a while that compresses my code and removes from the compressed code any files that should be rebuildable (i.e. object code files .exe and .obj). Does anybody want a copy? If so, where can I upload it?

Harry Potter

unread,
Aug 26, 2021, 4:11:30 PM8/26/21
to
On Thursday, August 26, 2021 at 4:08:14 PM UTC-4, Harry Potter wrote:
> Hi! I have a batch file I've been using for a while that compresses my code and removes from the compressed code any files that should be rebuildable (i.e. object code files .exe and .obj). Does anybody want a copy? If so, where can I upload it?

I should've mentioned: It also attaches the current date to the file and can store the object in a given subdirectory of a user-specified directory.

JJ

unread,
Aug 26, 2021, 9:27:03 PM8/26/21
to
Thios has nothing to do with batch file.
Moreover, that is an EXE, not a batch file.

Keep it on topic, please.

Herbert Kleebauer

unread,
Aug 27, 2021, 3:59:22 AM8/27/21
to
On 26.08.2021 22:08, Harry Potter wrote:

> Hi! I have a batch file I've been using for a while
> If so, where can I upload it?

There is no need to upload it somewhere. If you think it is
useful as it is or it shows some batch techniques which
are not trivial or commonly known, just post the code here.

Kerr-Mudd, John

unread,
Aug 27, 2021, 5:10:25 AM8/27/21
to
I think he already did, some decades back; it was a wrapper to an archive program (arj?)
and no doubt is fine for his needs.

--
Bah, and indeed Humbug.

Harry Potter

unread,
Aug 27, 2021, 7:27:02 AM8/27/21
to
It is a wrapper to 7Zip. And I *did* upload it before. And it *is* useful to me and fine for my needs. It is split into two parts: one gets the date, and the other does the actual compression. I may post them later. :)

Harry Potter

unread,
Aug 27, 2021, 8:04:04 AM8/27/21
to
Here are the batch files:

Backup Date in DATE2.bat:
------------------------------------------
@echo off
::This file returns the data in YYYY-MM-DD format into the DATE2 variable.
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set dt=%%a
set DATE2=%dt:~0,4%-%dt:~4,2%-%dt:~6,2%
-----------------------------------------
Backup with 7Zip.BAT:
------------------------------------
@echo off
echo This batch file will back up this folder to the back-up folder on your
echo hard drive.
echo.
set /p sys=Type in the system name. The backup will be placed there:
::Set cpa to the work path for this program. I recently changed it to a RAM
::drive.
::set cpa=c:%homepath%\desktop
set cpa=%temp%
::Make a work dir. and switch to it.
md "%cpa%\hptemp"
md "%cpa%\hptemp\%~nx1"
cd /d "%cpa%\hptemp\%~nx1"
::Copy all files to temp. workspace.
xcopy %1 /e /i
::Delete files that can be re-built.
del /s /q *.prg *.obj *.map *.d64 *.exe *.o
cd..
::Get current date. You may need to change the path.
::This line calls another batch in my package.
call "C:\MyPrgs\Batch\Backup Date in DATE2.bat"
::Do the actual compression.
"C:\Program Files\7-Zip\7z.exe" a "%~nx1_%DATE2%.7z" "%~nx1" -r -mx=9 -m0=lzma2
::Exit if error.
if errorlevel 1 goto end
::Store backed-up file.
::Note: this assumes that both the given backup dir. exists and so does any
::selection made at the prompt.
::You may use any folder you want.
echo %date2%
move /y "%~nx1_%DATE2%.7z" c:\MyPrgs\backup\%sys%
if errorlevel 1 goto end
cd..
::Delete work dir.
rd /s /q "%cpa%\hptemp"

:end
pause
--------------------------------
Simply copy the two batch files to a convenient folder on your hard drive, put a short-cut to the latter in the SendTo folder and edit the latter as follows:

* Where it asks for the system name, you can name any organization method you want.
* Edit the move command to write to any folder you want.

Have fun, and tell me what you think!

Harry Potter

unread,
Oct 9, 2021, 6:08:10 PM10/9/21
to
Were these batch files useful to anybody? I am an egotist and desire feedback. :)

Tom Del Rosso

unread,
Oct 12, 2021, 4:59:56 PM10/12/21
to
Harry Potter wrote:
> Were these batch files useful to anybody? I am an egotist and desire
> feedback. :)

:-)

OK. Complete batch files are probably useful only to their creator, but
subroutines and techniques are adaptable.


--
Defund the Thought Police


Kenny McCormack

unread,
Oct 13, 2021, 6:22:34 AM10/13/21
to
In article <sk4t0b$4f2$1...@dont-email.me>,
Tom Del Rosso <fizzbin...@that-google-mail-domain.com> wrote:
>Harry Potter wrote:
>> Were these batch files useful to anybody? I am an egotist and desire
>> feedback. :)
>
>:-)
>
>OK. Complete batch files are probably useful only to their creator, but
>subroutines and techniques are adaptable.

This is an excellent observation. I have long said (in the Unix/Linux
context, but the principle is the same): Nobody wants to run other people's
shell scripts.

As you say, the ideas and techniques are sharable, but whole scripts are
rarely going to be useful (and, more importantly, safe) for other people to
use.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/InsaneParty

Ammammata

unread,
Oct 15, 2021, 6:38:47 AM10/15/21
to
Il giorno Fri 27 Aug 2021 02:04:02p, *Harry Potter* ha inviato su
alt.msdos.batch.nt il messaggio news:e411ea98-1d77-46f6-b711-
d878af...@googlegroups.com. Vediamo cosa ha scritto:

> set cpa=%temp%
>::Make a work dir. and switch to it.
> md "%cpa%\hptemp"
> md "%cpa%\hptemp\%~nx1"
> cd /d "%cpa%\hptemp\%~nx1"

I presume this works fine ALWAYS, otherwise the next would be a mess

>::Copy all files to temp. workspace.
> xcopy %1 /e /i
>::Delete files that can be re-built.
> del /s /q *.prg *.obj *.map *.d64 *.exe *.o
>

did you tested all the possible events i.e. the user customized the %temp%
folder?

--
/-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\
-=- -=- -=- -=- -=- -=- -=- -=- - -=-
........... [ al lavoro ] ...........

Harry Potter

unread,
Oct 15, 2021, 11:13:44 AM10/15/21
to
As long as the folder assigned to %cda% exists, the del lines won't hurt the software being backed up. When I first created the batch file, IIRC, it deleted some important data. :( But it works, provided that the %cda% variable points to a folder that exists and the folders referred to in the batch file exist. BTW, you will need to change the folders listed in the batch file to ones that exist.

Tom Del Rosso

unread,
Oct 22, 2021, 10:16:51 PM10/22/21
to
Kenny McCormack wrote:
> In article <sk4t0b$4f2$1...@dont-email.me>,
> Tom Del Rosso <fizzbin...@that-google-mail-domain.com> wrote:
>> Harry Potter wrote:
>>> Were these batch files useful to anybody? I am an egotist and
>>> desire feedback. :)
>>
>> :-)
>>
>> OK. Complete batch files are probably useful only to their creator,
>> but subroutines and techniques are adaptable.
>
> This is an excellent observation. I have long said (in the Unix/Linux
> context, but the principle is the same): Nobody wants to run other
> people's shell scripts.
>
> As you say, the ideas and techniques are sharable, but whole scripts
> are rarely going to be useful (and, more importantly, safe) for other
> people to use.

I routinely use a few that would be dangerous for anyone who didn't
understand them, but I've written some that would be useful to a few
others.

Here is a demo of a technique I haven't seen elsewhere.

@echo off
rem ******************************************************
rem You can have 88 consecutive "FOR variables" from
rem character 38 [&] to character 125 [}] inclusive,
rem or 93 if you start at character 33 [!] and don't
rem use the unusable character 37 [%].
rem
rem This takes advantage of the fact that FOR variables
rem can be reassigned within a block as "(" and "F"
rem and "d" are below. This is necessary because the
rem maximum "tokens=" is 31 in a single FOR command.
rem
rem Most of the control characters work, but you can't
rem type them in most editors. Generating a batch with
rem the binary values shows that they work
rem except 9, 10, 11, 12, 13, 26, and of course 32.
rem
rem Curiously, 20 and 21 work separately
rem but tokens=20-21 or tokens=20,21 doesn't work,
rem so it looks like you can't use "tokens=20,*" either.
rem
rem Also, 44 [,] 59 [;] and 61 [=] work as references
rem but not as the base variable in the FOR line. For
rem example those 3 can be used like this:
rem for /f "tokens=1,2" %%^+ in ("text1 TEXT2") do (
rem echo Character 43 [^+] Token 1 [%%^+]
rem echo Character 44 [^,] Token 2 [%%^,]
rem )
rem for /f "tokens=1,2" %%^: in ("text1 TEXT2") do (
rem echo Character 58 [^:] Token 1 [%%^:]
rem echo Character 59 [^;] Token 2 [%%^;]
rem )
rem for /f "tokens=1,2" %%^< in ("text1 TEXT2") do (
rem echo Character 60 [^<] Token 1 [%%^<]
rem echo Character 61 [^=] Token 2 [%%^=]
rem )
rem All others below work in the FOR line.
rem ******************************************************

rem generate a sting of numbers to be used by other FOR commands
set "text="
for /L %%a in (1,1,256) do call set text=%%text%% %%a
echo %text%
echo.

echo Starting with BEL (ASCII 7) as FOR variable:
for /f "tokens=7" %%^. in ("%text%") do (
for /f "tokens=15" %%^¤ in ("%text%") do (
for /f "tokens=20" %%^¶ in ("%text%") do (
for /f "tokens=21" %%^§ in ("%text%") do (
echo Character 7 [^.] Token 7 [%%^.]
echo Character 15 [^¤] Token 15 [%%^¤]
echo Character 20 [^¶] Token 20 [%%^¶]
echo Character 21 [^§] Token 21 [%%^§]
)
)
)
)
echo --------------------------------
echo Starting with ! as FOR variable:
for /f "tokens=1-7,*" %%! in ("%text%") do (
for /f "tokens=1-30,*" %%( in ("%%(") do (
for /f "tokens=1-30,*" %%F in ("%%F") do (
for /f "tokens=1-30" %%d in ("%%d") do (
echo Character 33 [!] Token 1 [%%!]
echo Character 34 ["] Token 2 [%%"]
echo Character 35 [#] Token 3 [%%#]
echo Character 36 [$] Token 4 [%%$]
echo Character 37 [^%] Token 5 [%%^%]
echo Character 38 [^&] Token 6 [%%^&]
echo Character 39 ['] Token 7 [%%']
echo Character 40 [^(] Token 8 [%%^(]
echo Character 41 [^)] Token 9 [%%^)]
echo Character 42 [*] Token 10 [%%*]
echo Character 43 [+] Token 11 [%%+]
echo Character 44 [,] Token 12 [%%,]
echo Character 45 [-] Token 13 [%%-]
echo Character 46 [.] Token 14 [%%.]
echo Character 47 [/] Token 15 [%%/]
echo Character 48 [0] Token 16 [%%0]
echo Character 49 [1] Token 17 [%%1]
echo Character 50 [2] Token 18 [%%2]
echo Character 51 [3] Token 19 [%%3]
echo Character 52 [4] Token 20 [%%4]
echo Character 53 [5] Token 21 [%%5]
echo Character 54 [6] Token 22 [%%6]
echo Character 55 [7] Token 23 [%%7]
echo Character 56 [8] Token 24 [%%8]
echo Character 57 [9] Token 25 [%%9]
echo Character 58 [:] Token 26 [%%:]
echo Character 59 [;] Token 27 [%%;]
echo Character 60 [^<] Token 28 [%%^<]
echo Character 61 [=] Token 29 [%%=]
echo Character 62 [^>] Token 30 [%%^>]
echo Character 63 [?] Token 31 [%%?]
echo Character 64 [@] Token 32 [%%@]
echo Character 65 [A] Token 33 [%%A]
echo Character 66 [B] Token 34 [%%B]
echo Character 67 [C] Token 35 [%%C]
echo Character 68 [D] Token 36 [%%D]
echo Character 69 [E] Token 37 [%%E]
echo Character 70 [F] Token 38 [%%F]
echo Character 71 [G] Token 39 [%%G]
echo Character 72 [H] Token 40 [%%H]
echo Character 73 [I] Token 41 [%%I]
echo Character 74 [J] Token 42 [%%J]
echo Character 75 [K] Token 43 [%%K]
echo Character 76 [L] Token 44 [%%L]
echo Character 77 [M] Token 45 [%%M]
echo Character 78 [N] Token 46 [%%N]
echo Character 79 [O] Token 47 [%%O]
echo Character 80 [P] Token 48 [%%P]
echo Character 81 [Q] Token 49 [%%Q]
echo Character 82 [R] Token 50 [%%R]
echo Character 83 [S] Token 51 [%%S]
echo Character 84 [T] Token 52 [%%T]
echo Character 85 [U] Token 53 [%%U]
echo Character 86 [V] Token 54 [%%V]
echo Character 87 [W] Token 55 [%%W]
echo Character 88 [X] Token 56 [%%X]
echo Character 89 [Y] Token 57 [%%Y]
echo Character 90 [Z] Token 58 [%%Z]
echo Character 91 [[] Token 59 [%%[]
echo Character 92 [\] Token 60 [%%\]
echo Character 93 []] Token 61 [%%]]
echo Character 94 [^^] Token 62 [%%^^]
echo Character 95 [_] Token 63 [%%_]
echo Character 96 [^`] Token 64 [%%^`]
echo Character 97 [a] Token 65 [%%a]
echo Character 98 [b] Token 66 [%%b]
echo Character 99 [c] Token 67 [%%c]
echo Character 100 [d] Token 68 [%%d]
echo Character 101 [e] Token 69 [%%e]
echo Character 102 [f] Token 70 [%%f]
echo Character 103 [g] Token 71 [%%g]
echo Character 104 [h] Token 72 [%%h]
echo Character 105 [i] Token 73 [%%i]
echo Character 106 [j] Token 74 [%%j]
echo Character 107 [k] Token 75 [%%k]
echo Character 108 [l] Token 76 [%%l]
echo Character 109 [m] Token 77 [%%m]
echo Character 110 [n] Token 78 [%%n]
echo Character 111 [o] Token 79 [%%o]
echo Character 112 [p] Token 80 [%%p]
echo Character 113 [q] Token 81 [%%q]
echo Character 114 [r] Token 82 [%%r]
echo Character 115 [s] Token 83 [%%s]
echo Character 116 [t] Token 84 [%%t]
echo Character 117 [u] Token 85 [%%u]
echo Character 118 [v] Token 86 [%%v]
echo Character 119 [w] Token 87 [%%w]
echo Character 120 [x] Token 88 [%%x]
echo Character 121 [y] Token 89 [%%y]
echo Character 122 [z] Token 90 [%%z]
echo Character 123 [{] Token 91 [%%{]
echo Character 124 [^|] Token 92 [%%^|]
echo Character 125 [}] Token 93 [%%}] works up to here
echo Character 126 [~] Token 94 [%%~] doesn't work from here
forward
echo Character 127 [¦] Token 95 [%%¦]
echo Character 128 [Ç] Token 96 [%%Ç]
echo Character 129 [ü] Token 97 [%%ü]
echo Character 130 [é] Token 98 [%%é]
)
)
)
)
pause


Kerr-Mudd, John

unread,
Oct 23, 2021, 4:41:57 AM10/23/21
to
On Fri, 22 Oct 2021 22:16:48 -0400
[...]

>
> rem generate a sting of numbers to be used by other FOR commands

'string'!

> set "text="

[...]

> echo Character 125 [}] Token 93 [%%}] works up to here
> echo Character 126 [~] Token 94 [%%~] doesn't work from here
> forward
> echo Character 127 [¦] Token 95 [%%¦]
> echo Character 128 [Ç] Token 96 [%%Ç]
> echo Character 129 [ü] Token 97 [%%ü]
> echo Character 130 [é] Token 98 [%%é]

Might 156 [£] {UKP} work?

[]

Tom Del Rosso

unread,
Oct 23, 2021, 9:00:14 PM10/23/21
to
To reduce length I'm forgoing quotes.

I did that experiment many years ago, but ISTR that 93 was the maximum
*consecutive* tokens that could be referenced.

Higher characters might work but I don't remember the limitations.

Of course the characters above 127 will be mangled by usenet. You can
generate a batch file via another program. I did this years ago with a
BASIC program. But the resulting batch only proves you can get one token
out of each.

==================BEGIN BASIC==================
CLS
OPEN "d:\for256.cmd" FOR OUTPUT AS #1
t = 1
PRINT #1, "@echo off"
FOR c = 1 TO 255
REM GENERATE THESE LINES FOR EACH CHAR
REM for /f "tokens=1" %%^P in ("text") do (
REM echo Character 80 [^P] Token 1 [%%^P]
REM )
PRINT #1, "for /f "; CHR$(34); "tokens=1"; CHR$(34); " %%^"; CHR$(c); "
in ("; CHR$(34); "text"; CHR$(34); ") do ("
PRINT #1, CHR$(9); "echo Character"; c; "[^"; CHR$(c); "] Token"; t;
"[%%^"; CHR$(c); "]"
PRINT #1, ")"
NEXT
PRINT #1, "pause"
==================END BASIC==================

By generating the batch that way and adding a few things manually it
doesn't seem able to reference more than 1 token. The first part of this
fails beyond 1 token, but the second part (which is excerpted from that
generated by the BASIC script) works somewhat.


@echo off
rem generate a string of numbers to be used by other FOR commands
set "text="
for /L %%a in (1,1,256) do call set text=%%text%% %%a
echo %text%
echo.

echo -------first part--------

for /f "tokens=1-31" %%^- in ("%text%") do (
echo Character 150 [^-] Token 1 [%%^-]
echo Character 151 [^-] Token 2 [%%^-]
echo Character 152 [^~] Token 3 [%%^~]
echo Character 153 [^T] Token 4 [%%^T]
echo Character 154 [^s] Token 5 [%%^s]
echo Character 155 [^>] Token 6 [%%^>]
echo Character 156 [^o] Token 7 [%%^o]
echo Character 157 [^ ] Token 8 [%%^ ]
echo Character 158 [^z] Token 9 [%%^z]
echo Character 159 [^Y] Token 10 [%%^Y]
echo Character 160 [^ ] Token 11 [%%^ ]
echo Character 161 [^Ą] Token 12 [%%^Ą]
echo Character 162 [^Ē] Token 13 [%%^Ē]
echo Character 163 [^Ģ] Token 14 [%%^Ģ]
echo Character 164 [^Ī] Token 15 [%%^Ī]
echo Character 165 [^Ĩ] Token 16 [%%^Ĩ]
echo Character 166 [^Ķ] Token 17 [%%^Ķ]
echo Character 167 [^§] Token 18 [%%^§]
echo Character 168 [^Ļ] Token 19 [%%^Ļ]
echo Character 169 [^Đ] Token 20 [%%^Đ]
echo Character 170 [^Š] Token 21 [%%^Š]
echo Character 171 [^Ŧ] Token 22 [%%^Ŧ]
echo Character 172 [^Ž] Token 23 [%%^Ž]
echo Character 173 [^­] Token 24 [%%^­]
echo Character 174 [^Ū] Token 25 [%%^Ū]
echo Character 175 [^Ŋ] Token 26 [%%^Ŋ]
echo Character 176 [^°] Token 27 [%%^°]
echo Character 177 [^ą] Token 28 [%%^ą]
echo Character 178 [^ē] Token 29 [%%^ē]
echo Character 179 [^ģ] Token 30 [%%^ģ]
echo Character 180 [^ī] Token 31 [%%^ī]
)

echo -------second part--------

for /f "tokens=1" %%^- in ("text") do (
echo Character 150 [^-] Token 1 [%%^-]
)
for /f "tokens=1" %%^- in ("text") do (
echo Character 151 [^-] Token 1 [%%^-]
)
for /f "tokens=1" %%^~ in ("text") do (
echo Character 152 [^~] Token 1 [%%^~]
)
for /f "tokens=1" %%^T in ("text") do (
echo Character 153 [^T] Token 1 [%%^T]
)
for /f "tokens=1" %%^s in ("text") do (
echo Character 154 [^s] Token 1 [%%^s]
)
for /f "tokens=1" %%^> in ("text") do (
echo Character 155 [^>] Token 1 [%%^>]
)
for /f "tokens=1" %%^o in ("text") do (
echo Character 156 [^o] Token 1 [%%^o]
)
for /f "tokens=1" %%^ in ("text") do (
echo Character 157 [^ ] Token 1 [%%^ ]
)
for /f "tokens=1" %%^z in ("text") do (
echo Character 158 [^z] Token 1 [%%^z]
)
for /f "tokens=1" %%^Y in ("text") do (
echo Character 159 [^Y] Token 1 [%%^Y]
)
for /f "tokens=1" %%^ in ("text") do (
echo Character 160 [^ ] Token 1 [%%^ ]
)
for /f "tokens=1" %%^Ą in ("text") do (
echo Character 161 [^Ą] Token 1 [%%^Ą]
)
for /f "tokens=1" %%^Ē in ("text") do (
echo Character 162 [^Ē] Token 1 [%%^Ē]
)
for /f "tokens=1" %%^Ģ in ("text") do (
echo Character 163 [^Ģ] Token 1 [%%^Ģ]
)
for /f "tokens=1" %%^Ī in ("text") do (
echo Character 164 [^Ī] Token 1 [%%^Ī]
)
for /f "tokens=1" %%^Ĩ in ("text") do (
echo Character 165 [^Ĩ] Token 1 [%%^Ĩ]
)
for /f "tokens=1" %%^Ķ in ("text") do (
echo Character 166 [^Ķ] Token 1 [%%^Ķ]
)
for /f "tokens=1" %%^§ in ("text") do (
echo Character 167 [^§] Token 1 [%%^§]
)
for /f "tokens=1" %%^Ļ in ("text") do (
echo Character 168 [^Ļ] Token 1 [%%^Ļ]
)
for /f "tokens=1" %%^Đ in ("text") do (
echo Character 169 [^Đ] Token 1 [%%^Đ]
)
for /f "tokens=1" %%^Š in ("text") do (
echo Character 170 [^Š] Token 1 [%%^Š]
)
for /f "tokens=1" %%^Ŧ in ("text") do (
echo Character 171 [^Ŧ] Token 1 [%%^Ŧ]
)
for /f "tokens=1" %%^Ž in ("text") do (
echo Character 172 [^Ž] Token 1 [%%^Ž]
)
for /f "tokens=1" %%^­ in ("text") do (
echo Character 173 [^­] Token 1 [%%^­]
)
for /f "tokens=1" %%^Ū in ("text") do (
echo Character 174 [^Ū] Token 1 [%%^Ū]
)
for /f "tokens=1" %%^Ŋ in ("text") do (
echo Character 175 [^Ŋ] Token 1 [%%^Ŋ]
)
for /f "tokens=1" %%^° in ("text") do (
echo Character 176 [^°] Token 1 [%%^°]
)
for /f "tokens=1" %%^ą in ("text") do (
echo Character 177 [^ą] Token 1 [%%^ą]
)
for /f "tokens=1" %%^ē in ("text") do (
echo Character 178 [^ē] Token 1 [%%^ē]
)
for /f "tokens=1" %%^ģ in ("text") do (
echo Character 179 [^ģ] Token 1 [%%^ģ]
)
for /f "tokens=1" %%^ī in ("text") do (
echo Character 180 [^ī] Token 1 [%%^ī]
)
pause


0 new messages