Discussion:
Batch file for compressing code
(too old to reply)
Harry Potter
2021-08-26 20:08:13 UTC
Permalink
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
2021-08-26 20:11:29 UTC
Permalink
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
2021-08-27 01:27:01 UTC
Permalink
Post by Harry Potter
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?
Thios has nothing to do with batch file.
Moreover, that is an EXE, not a batch file.

Keep it on topic, please.
Herbert Kleebauer
2021-08-27 07:59:18 UTC
Permalink
Post by Harry Potter
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
2021-08-27 09:10:23 UTC
Permalink
On Fri, 27 Aug 2021 09:59:18 +0200
Post by Herbert Kleebauer
Post by Harry Potter
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.
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
2021-08-27 11:27:01 UTC
Permalink
Post by Kerr-Mudd, John
On Fri, 27 Aug 2021 09:59:18 +0200
Post by Herbert Kleebauer
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.
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.
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
2021-08-27 12:04:02 UTC
Permalink
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
2021-10-09 22:08:09 UTC
Permalink
Were these batch files useful to anybody? I am an egotist and desire feedback. :)
Tom Del Rosso
2021-10-12 21:00:03 UTC
Permalink
Post by Harry Potter
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
2021-10-13 10:22:33 UTC
Permalink
Post by Tom Del Rosso
Post by Harry Potter
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
Tom Del Rosso
2021-10-23 02:16:48 UTC
Permalink
Post by Kenny McCormack
Post by Tom Del Rosso
Post by Harry Potter
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
2021-10-23 08:41:57 UTC
Permalink
On Fri, 22 Oct 2021 22:16:48 -0400
Post by Tom Del Rosso
Post by Kenny McCormack
Post by Tom Del Rosso
Post by Harry Potter
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
[...]
Post by Tom Del Rosso
rem generate a sting of numbers to be used by other FOR commands
'string'!
Post by Tom Del Rosso
set "text="
[...]
Post by Tom Del Rosso
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?

[]
--
Bah, and indeed Humbug.
Tom Del Rosso
2021-10-24 01:00:10 UTC
Permalink
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

Ammammata
2021-10-15 10:38:46 UTC
Permalink
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-
Post by Harry Potter
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
Post by Harry Potter
::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
2021-10-15 15:13:43 UTC
Permalink
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.
Loading...