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

Check file size, return value?

93 views
Skip to first unread message

Clueless in Seattle

unread,
Oct 30, 2001, 3:58:20 PM10/30/01
to
I'd like to add a routine to a batch file that would check the size of
a certain file, and then if the file is larger than 64 K, branch to
another routine.

So I guess I'm asking two questions:

1. Is it possible for a batch file to check the size of a
file?

2. If so, can the size checking routine be written so as to
return different values, depending on the the size of the file being
checked?

--
Please post your reply to this newsgroup.
All emails sent to spamless_...@yahoo.com are automatically deleted as spam prevention. If you would like to email me personally, please post a request for my email address in this newsgroup.

William Allen

unread,
Oct 30, 2001, 4:26:59 PM10/30/01
to
Clueless in Seattle wrote in message

> I'd like to add a routine to a batch file that would check the size of
> a certain file, and then if the file is larger than 64 K, branch to
> another routine.

This simple routine tests for conditions:
1) Less than 64K
2) Greater than or equal to 64K

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (%1)==() GOTO USAGE
IF NOT EXIST %1 GOTO USAGE
ECHO.RBX>%TEMP%.\S
ECHO.>>%TEMP%.\S
ECHO.q>>%TEMP%.\S
TYPE %TEMP%.\S | debug %1 | find "BX 0000">NUL
IF ERRORLEVEL 1 ECHO. File is 64Kbytes or greater
IF NOT ERRORLEVEL 1 ECHO. File is less than 64Kbytes

GOTO EOF
:USAGE
ECHO. Usage %0 Filespec
ECHO. Tests whether or not file is less than 64Kbytes
ECHO.

:EOF

====End cut-and-paste (omit this line)
To use the code above, cut-and-paste the text between the ==== lines
into a file with extension .BAT and base name of your choice. Lines
that don't begin with two spaces have wrapped in transmission. The
code was created and tested in Win9x GUI.

--
William Allen


William Allen

unread,
Oct 30, 2001, 4:29:07 PM10/30/01
to
William Allen wrote in message
...snip

> This simple routine tests for conditions:
> 1) Less than 64K
> 2) Greater than or equal to 64K

Note that it fails for files greater than around 600Kbytes.

--
William Allen


Clueless in Seattle

unread,
Oct 30, 2001, 10:22:54 PM10/30/01
to
William Allen wrote:

> This simple routine tests for conditions:
> 1) Less than 64K
> 2) Greater than or equal to 64K

That did the trick!

Many thanks!

laura fairhead

unread,
Oct 31, 2001, 12:22:13 AM10/31/01
to
On Tue, 30 Oct 2001 12:58:20 -0800, Clueless in Seattle <spamless_...@yahoo.com> wrote:

>I'd like to add a routine to a batch file that would check the size of
>a certain file, and then if the file is larger than 64 K, branch to
>another routine.
>
>So I guess I'm asking two questions:
>
> 1. Is it possible for a batch file to check the size of a
>file?
>
> 2. If so, can the size checking routine be written so as to
>return different values, depending on the the size of the file being
>checked?
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It is possible to get the file size of a file with DEBUG, although
this will read the entire file and also will fail if the file cannot
fit into base memory (if the file is greater than about 400k).

Another way to do it would be DIR /-W file and coaxing the size
field from that output to an environment variable. This is a
difficult technique to get working right esp. so that it works
on many different systems.

You could do also do it with a small machine code utility, for
example the following will check if the file is >64k and return
ERRORLEVEL 0 if not and ERRORLEVEL 1 if so. Then you can just
branch in batch as you normally would by IF ERRORLEVEL 1 GOTO (ismorethan64k)


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@ECHO OFF
SET FILE64K=%TEMP%.\@TMP0.COM
ECHO:`h}aXP5y`P]4nP_XW(F4(F6(F=(FF)FH(FL(Fe(FR0FTs*}`A?+,>%FILE64K%
ECHO:fkOU):G*@Crv,*t$HU[rlf~#IubfRfXf(V#fj}fX4{PY$@fPfZsZfHwu>>%FILE64K%
ECHO:{5,LC@$3pqiMCLePM@}.1mz/B}M$8bP9[U'pk7\6n$sDMBia[EVgSr(]>>%FILE64K%
ECHO:.NPVCF;YZ4t$fJb$$/*)#>>%FILE64K%
::
%FILE64K% %1
IF ERRORLEVEL 1 ECHO FILE %1 IS GREATER THAN 64K BYTES SIZE
IF NOT ERRORLEVEL 1 ECHO FILE %1 IS NOT GREATER THAN 64K BYTES SIZE
::
DEL %FILE64K%

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

The helper utility could be extended to return the size but
if it only did that you might find it difficult to do the
numeric comparison in batch.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MASM 6+ sOURCE code for 64k size check;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OPTION SCOPED
OPTION SEGMENT:USE16
.486

cseg SEGMENT BYTE

ASSUME NOTHING
ORG 0100h

kode PROC NEAR

;; advance SI to start of 1st parameter
MOV SI,081h
lop:
LODSB
CMP AL,020h;JZ lop
CMP AL,9;JZ lop
DEC SI
;; save start in DX for fileopen call below
MOV DX,SI
;; advance SI to end of 1st parameter
lop2:
LODSB
CMP AL,021h;JNC lop2
;; open file named
MOV AX,03D00h
MOV BYTE PTR [SI-1],AL
INT 021h
;; set file pointer to EOF
XCHG BX,AX
MOV AX,04202h
CWD
XOR CX,CX
INT 021h
;; set CF if file >64k in size
ADD DX,-1
;; return to DOS with ERRORLEVEL=0 for filesize<=64k
;; and ERRORLEVEL=255 for filesize>64k
MOV AH,04Ch
SBB AL,AL
INT 021h

kode ENDP

cseg ENDS

END FAR PTR kode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To assemble first translate ;; -> ; and ; -> \n
Assemble .COM file using MASM6+ and convert .COM file
to ascii-code using my CM3 utility ( http://lf.8k.com/TOOLS )
eg-
SED "s/;;/\x01/g;s/;/\n/g;s/\x01/;/g" FILENAME >FILENAME.ASM
MASM FILENAME;
LINK /T FILENAME;
CM3 FILENAME.COM >BATCH.BAT

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

byefrom

--
: ${L:-aura} # http://lf.8k.com:80
: # http://lf.1accesshost.com

laura fairhead

unread,
Oct 31, 2001, 12:47:01 AM10/31/01
to
On Wed, 31 Oct 2001 05:22:13 GMT, laura_f...@my-deja.com (laura fairhead) wrote:

>On Tue, 30 Oct 2001 12:58:20 -0800, Clueless in Seattle <spamless_...@yahoo.com> wrote:
>
>>I'd like to add a routine to a batch file that would check the size of
>>a certain file, and then if the file is larger than 64 K, branch to
>>another routine.

[]


>
>cseg ENDS
>
>END FAR PTR kode
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>To assemble first translate ;; -> ; and ; -> \n
>Assemble .COM file using MASM6+ and convert .COM file
>to ascii-code using my CM3 utility ( http://lf.8k.com/TOOLS )

that link should be;

http://lf.8k.com/TOOLS/TOOLS.HTM

cu from

Herbert Kleebauer

unread,
Oct 31, 2001, 5:24:32 AM10/31/01
to
laura fairhead wrote:

> >Assemble .COM file using MASM6+ and convert .COM file
> >to ascii-code using my CM3 utility ( http://lf.8k.com/TOOLS )
>
> that link should be;
>
> http://lf.8k.com/TOOLS/TOOLS.HTM

Because of the binary paranoia in this group, I have disassembled
the code. There a three sections. Section 1 modifies section 2
by subtracting 0x7d from some bytes. Section 2 generates
section 3 by decoding the rest of the file. 6 ascii bytes are
are converted to 4 binary bytes (modulo 0x55). Section 3
consist of a small header part (which calls the copy routine),
the encoded user program and the copy routine.

*********************** section 1 *************************
295b : 00000100 movem.w r0-r7,-(sp) (60)
295b : 00000101 move.w #$617d,-(sp) (68 7d 61)
295b : 00000104 move.w (sp)+,r0 (58)
295b : 00000105 move.w r0,-(sp) (50)
295b : 00000106 eor.w #$6079,r0 (35 79 60)
295b : 00000109 move.w r0,-(sp) (50)
295b : 0000010a move.w (sp)+,r4 (5d)
295b : 0000010b eor.b #$6e,r0 (34 6e)
295b : 0000010d move.w r0,-(sp) (50)
295b : 0000010e move.w (sp)+,r6 (5f)
295b : 0000010f move.w (sp)+,r0 (58)
295b : 00000110 move.w r6,-(sp) (57)
295b : 00000111 sub.b r0,$34(r4.w){s7} (28 46 34)
295b : 00000114 sub.b r0,$36(r4.w){s7} (28 46 36)
295b : 00000117 sub.b r0,$3d(r4.w){s7} (28 46 3d)
295b : 0000011a sub.b r0,$46(r4.w){s7} (28 46 46)
295b : 0000011d sub.w r0,$48(r4.w){s7} (29 46 48)
295b : 00000120 sub.b r0,$4c(r4.w){s7} (28 46 4c)
295b : 00000123 sub.b r0,$65(r4.w){s7} (28 46 65)
295b : 00000126 sub.b r0,$52(r4.w){s7} (28 46 52)
295b : 00000129 eor.b r0,$54(r4.w){s7} (30 46 54)
295b : 0000012c bcc.b $0158 (73 2a)

295b : 0000012e dc.b $7d (7d)
295b : 0000012f dc.b $60 (60)
295b : 00000130 dc.b $41 (41)
295b : 00000131 dc.b $3f (3f)
295b : 00000132 dc.b $2b (2b)
295b : 00000133 dc.b $2c (2c)
295b : 00000134 dc.b $0d (0d)
295b : 00000135 dc.b $0a (0a)

********* section 2 after decoding by section 1 *********
295b : 00000136 mulsq.l #$55,r1,r1 (66 6b d2 55)
295b : 0000013a move.b (r5.w)+-,r0 (ac)
295b : 0000013b cmp.b $2a(r3.w),r0 (3a 47 2a)
295b : 0000013e inc.w r0 (40)
295b : 0000013f inc.w r3 (43)
295b : 00000140 bcs.b $013b (72 f9)
295b : 00000142 sub.b #$2a,r0 (2c 2a)
295b : 00000144 beq.b $016a (74 24)
295b : 00000146 dec.w r0 (48)
295b : 00000147 move.w r4,-(sp) (55)
295b : 00000148 move.w (sp)+,r3 (5b)
295b : 00000149 bcs.b $013a (72 ef)
295b : 0000014b add.l r0,r1 (66 01 c2)
295b : 0000014e dec.w r2 (49)
295b : 0000014f bne.b $0136 (75 e5)
295b : 00000151 move.l r1,-(sp) (66 52)
295b : 00000153 move.l (sp)+,r0 (66 58)
295b : 00000155 move.l r0,(r6.w)+-{s1} (66 ab)
295b : 00000157 move.w r5,-(sp) (56)
295b : 00000158 move.w (sp)+,r5 (5e)
295b : 00000159 moveq.l #$7d,-(sp) (66 6a 7d)
295b : 0000015c move.l (sp)+,r0 (66 58)
295b : 0000015e eor.b #$7b,r0 (34 7b)
295b : 00000160 move.w r0,-(sp) (50)
295b : 00000161 move.w (sp)+,r2 (59)
295b : 00000162 and.b #$40,r0 (24 40)
295b : 00000164 move.l r0,-(sp) (66 50)
295b : 00000166 move.l (sp)+,r1 (66 5a)
295b : 00000168 bcc.b $0147 (73 dd)

********* section 3 after decoding by section 2 *********
***** header
295b : 0000016a move.w #$0005,r2 (b9 05 00)
295b : 0000016d move.w #$0100,r6 (bf 00 01)
295b : 00000170 bsr.w $0178 (e8 05 00)

***** user program
295b : 00000173 br.b $0173 (eb fe)
295b : 00000175 nop (90)
295b : 00000176 nop (90)
295b : 00000177 rts.w (c3)

***** copy routine
295b : 00000178 move.w (sp)+,r5 (5e)
295b : 00000179 rep(eq)_r2 (f3)
295b : 0000017a move.b (r5.w)+-,(r6.w)+-{s1} (a4)
295b : 0000017b movem.w (sp)+,r0-r7 (61)
295b : 0000017c br.w $0100 (e9 81 ff)

Outsider

unread,
Oct 30, 2001, 7:16:28 AM10/30/01
to
laura fairhead wrote:
>
> On Tue, 30 Oct 2001 12:58:20 -0800, Clueless in Seattle <spamless_...@yahoo.com> wrote:
>
> >I'd like to add a routine to a batch file that would check the size of
> >a certain file, and then if the file is larger than 64 K, branch to
> >another routine.
> >
> >So I guess I'm asking two questions:
> >
> > 1. Is it possible for a batch file to check the size of a
> >file?
> >
> > 2. If so, can the size checking routine be written so as to
> >return different values, depending on the the size of the file being
> >checked?
> >
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> It is possible to get the file size of a file with DEBUG, although
> this will read the entire file and also will fail if the file cannot
> fit into base memory (if the file is greater than about 400k).
>
> Another way to do it would be DIR /-W file and coaxing the size
> field from that output to an environment variable. This is a
> difficult technique to get working right esp. so that it works
> on many different systems.

I haven't tried this on many different systems, but I think it will
work on many different systems with English language DOS. Line wrapping
off please. Ansi.sys optional; if you don't use ansi.sys you may comment
out the lines beginning with % opt%.

:: compsize.bat
@ECHO off
IF "%1"=="ReCuRs1" GOTO recurs1
IF "%1"=="ReCuRs[" GOTO recurs2
IF not "%1"=="" GOTO start

:help
ECHO.
ECHO. Syntax: compsize filełdrv: [n]
ECHO (where file or drive exists and n is number in bytes)
ECHO.
ECHO. Compares a specified amount of bytes to size of an existing file
ECHO. or space free on a specified drive and reports which is larger,
ECHO. or if equal. Sets variable p1 (parameter 1) to 'drv' or 'fil'.
ECHO. Sets n1 (number of bytes represented by parameter1) to 'large'
ECHO. or 'small' or 'equal', relative to parameter 2. Wildcards are
ECHO. not supported.
ECHO.
ECHO. If no parameter 2 is given, the bytes for parm1 will still be
ECHO. obtained, and the n1 variable will not be set. No parameters
ECHO. brings up this help screen.
ECHO.
ECHO. Useage: compsize c:\bat\temp.tmp
ECHO. compsize e: 53428
ECHO. compsize temp.txt 134
ECHO. compsize {displays this help screen}
ECHO.
GOTO end

:start
%COMSPEC%/CIF not "%2"=="" ECHO +%2 |FIND "+0" >nul
IF not "%2"=="" IF not errorlevel 1 ECHO. leading zeros not supported
IF not "%2"=="" IF not errorlevel 1 GOTO help
SET byte=
SET p1=
SET n1=
ECHO %1+ |FIND ":+" >nul
IF not errorlevel 1 GOTO drive
FOR %%f in (%1) do IF %1==%%f GOTO file
ECHO. ** wildcards not supported **
GOTO help

:drive
ECHO ; |CHOICE.COM /C%1; >nul
IF errorlevel 4 ECHO. syntax error
IF errorlevel 4 GOTO help
IF errorlevel 1 IF not errorlevel 3 ECHO. ** syntax error **
IF errorlevel 1 IF not errorlevel 3 GOTO help
CTTY nul
%COMSPEC%/F/CDIR/ADH/W/-P %1 |FIND.EXE ":\" >nul
IF errorlevel 1 ECHO. ** invalid drive **>con
IF errorlevel 1 CTTY con
% opt%IF errorlevel 1 ECHO [2A
IF errorlevel 1 GOTO help

:again
DIR/A/W %1\ |FIND "bytes free" >%temp%.\bytes0.tmp
IF exist %1\flag0$#.flg DEL %1\flag0$#.flg
IF not errorlevel 1 SET p1=drv
IF not errorlevel 1 CTTY con
% opt%IF not errorlevel 1 ECHO [2A
IF not errorlevel 1 GOTO proceed
:: check if writeable
%COMSPEC% nul /F/CDEL %1\flag0$#.flg
IF exist %1\flag0$#.flg ECHO. error: undeletable flag file, flag0$#.flg on %1\
IF exist %1\flag0$#.flg GOTO help
SET write=
%COMSPEC% nul /F/CTYPE nul >%1\flag0$#.flg
IF exist %1\flag0$#.flg ECHO. no files on %1>con
IF exist %1\flag0$#.flg GOTO again
CTTY con
% opt% ECHO [2A
ECHO. unable to determine free space
ECHO. no files on %1 - drive not writeable
IF "%write%"=="no" ECHO. no files on %1
GOTO end

:file
IF not exist %1 ECHO. ** file not found **
IF not exist %1 GOTO help
SET p1=fil
DIR/A-D/W/-P %1. |FIND " 1 file(s) " >%temp%.\bytes0.tmp

:proceed
ECHO @PROMPT SET byte=%%%%byte%%%%>%temp%.\bytes1.bat
FC/N/LB1 %temp%.\bytes0.tmp nul |find "1:">>%temp%.\bytes1.bat
CTTY nul
%COMSPEC%/C%temp%.\bytes1.bat> %temp%.\bytes2.bat
CTTY con
% opt% ECHO [2A
CALL %temp%.\bytes2.bat
DEL %temp%.\bytes?.*
CALL %0 ReCuRs1 %byte%
GOTO parse

:recurs1
FOR %%n in (1 2) do SHIFT
SET byte=%1

:loop
SHIFT
IF "%1"=="file(s)" SET byte=
IF "%1"=="file(s)" SHIFT
IF "%1"=="bytes" GOTO end
SET byte=%byte%%1
GOTO loop

:parse
ECHO ; | CHOICE/C;%byte%; %0;ReCuRs>%temp%.\parse.bat
SET byte=
CALL %temp%.\parse.bat
DEL %temp%.\parse.bat
IF not "%2"=="" GOTO compare
IF "%p1%"=="fil" ECHO. '%1' is %byte% bytes
IF "%p1%"=="drv" ECHO. drive %1 has %byte% bytes free
GOTO end

:recurs2
SHIFT
IF "%1"=="]?" GOTO end
FOR %%n in (0 1 2 3 4 5 6 7 8 9) do IF %1==%%n SET byte=%byte%%1
GOTO recurs2

:compare
IF "%p1%"=="drv" IF "%byte%"=="%2" ECHO. free space on '%1' at %byte% bytes is equal to '%2'
IF "%p1%"=="fil" IF "%byte%"=="%2" ECHO. file '%1' at %byte% bytes is equal to '%2'
IF "%byte%"=="%2" SET n1=equal
IF "%byte%"=="%2" ECHO.
IF "%byte%"=="%2" GOTO end
IF exist %temp%.\compstr?.tmp DEL %temp%.\compstr?.tmp
ECHO %byte%>%temp%.\compstr1.tmp
ECHO %2>>%temp%.\compstr2.tmp
DIR/A-D/OS/B %temp%.\compstr?.tmp | FIND/N/V "" |FIND/I "1]compstr2.tmp" >nul
IF "%p1%"=="drv" IF not errorlevel 1 ECHO. free space on '%1' at %byte% bytes is larger than '%2'
IF "%p1%"=="fil" IF not errorlevel 1 ECHO. file '%1' at %byte% bytes is larger than '%2'
IF not errorlevel 1 SET n1=large
IF not errorlevel 1 GOTO last2
DIR/A-D/O-S/B %temp%.\compstr?.tmp | FIND/N/V "" |FIND/I "1]compstr2.tmp" >nul
IF "%p1%"=="fil" IF not errorlevel 1 ECHO. file '%1' at %byte% bytes is smaller than '%2'
IF "%p1%"=="drv" IF not errorlevel 1 ECHO. free space on '%1' at %byte% bytes is smaller than '%2'
IF not errorlevel 1 SET n1=small
IF not errorlevel 1 GOTO last2
ECHO %byte%>%temp%.\compstr1.tmp
ECHO %2>>%temp%.\compstr1.tmp
SORT.EXE < %temp%.\compstr1.tmp | FIND/N/V "" |FIND/I "1]%2" >nul
IF "%p1%"=="drv" IF not errorlevel 1 ECHO. free space on '%1' at %byte% bytes is larger than '%2'
IF "%p1%"=="fil" IF not errorlevel 1 ECHO. file '%1' at %byte% bytes is larger than '%2'
IF not errorlevel 1 SET n1=small
IF "%p1%"=="drv" IF errorlevel 1 ECHO. free space on '%1' at %byte% bytes is smaller than '%2'
IF "%p1%"=="fil" IF errorlevel 1 ECHO. file '%1' at %byte% bytes is smaller than '%2'
IF errorlevel 1 SET n1=small
GOTO last2

:last
SET n1=

:last2
SET p1=
DEL %temp%.\compstr?.tmp
ECHO.

:end
::

--
<!-Outsider//->
MS-DOS 6.22, Windows for Workgroups 3.11, Netscape Communicator 4.08

Outsider

unread,
Oct 30, 2001, 7:30:24 AM10/30/01
to
Outsider wrote:
>

...snip

> > Another way to do it would be DIR /-W file and coaxing the size
> > field from that output to an environment variable. This is a
> > difficult technique to get working right esp. so that it works
> > on many different systems.
>
> I haven't tried this on many different systems, but I think it will
> work on many different systems with English language DOS. Line wrapping
> off please. Ansi.sys optional; if you don't use ansi.sys you may comment
> out the lines beginning with % opt%.


BTW, the %dircmd% variable was not considered. If you use it, then
you should take add code to save and restore it at the beginning and
end respectively.

Clueless in Seattle

unread,
Oct 31, 2001, 10:16:01 AM10/31/01
to
Wow! I have no idea what you just wrote. This is a real eye opener
for me. Up to now I had operated on the assumption that I was limited
in what I could do in a batch file by the tiny set of batch commands
provided by my operating system.

But from the looks of the code you posted in your message, it looks as
if one could do just about anything if they knew how.

Thanks for writing this code for me, and especially for showing me
that there is far more to writing batch files than I ever could have
imagined.

P.S. Many thanks to all the others who contributed code and comments
to this thread. I'm disabled by chronic pain and fatique that
severely limit the amount of time I can spend sitting up at my
computer, so I'm not able to thank each of you individually for your
contributions. But I greatly appreciate them and have copied them to
a floppy so I can study them in bed on a donated laptop that I'm
trying (without much success) to get working.

Dr John Stockton

unread,
Oct 31, 2001, 8:08:17 AM10/31/01
to
JRS: In article <3BDF146C...@oco.net>, seen in
news:alt.msdos.batch, Clueless in Seattle <spamless_...@yahoo.com>
wrote at Tue, 30 Oct 2001 12:58:20 :-

> 1. Is it possible for a batch file to check the size of a
>file?

Yes.

> 2. If so, can the size checking routine be written so as to
>return different values, depending on the the size of the file being
>checked?

Yes. It can return the size of the file. Example : file hebclndr.ok2

HUNT hebclndr.ok2 | COLS 34-43 . | STOW xx
HUNT.PAS (q.v.) #8q >=2001-10-17 from C:\UTYS\HUNT.EXE
STOW : Environ Status = 0 OK=TRUE xx= 20466

C:\pas-prog>ENVICALC %xx% 65536 - L1 Exx
xx=-, Environ Status = 0, OK=TRUE

In the first block, the first line puts the second directly to screen;
XX is set to the size of the file.

The second block sets XX to - for files < 64K, to + for files >= 64K.

To do it in one line :

HUNT hebclndr.ok2 | COLS 34-43 . | MASSEXEC ENVICALC ! 65536 - L1 Exx


HUNT COLS STOW MASSEXEC ENVICALC HEBCLNDR via sig line 3.

HEBCLNDR opens the door to putting the MJD or Gregorian Date of 1 Tishri
for a given year (AM or AD, but not full range) into the Environment,
which would be challenging in pure DOS (unless Israeli?).

--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL: http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS, EXE in <URL: http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm &c.

Mike Jones

unread,
Oct 31, 2001, 1:40:54 PM10/31/01
to

"Herbert Kleebauer" <kl...@unibwm.de> wrote in message
news:3BDFD1...@unibwm.de...

> laura fairhead wrote:
>
> > >Assemble .COM file using MASM6+ and convert .COM file
> > >to ascii-code using my CM3 utility ( http://lf.8k.com/TOOLS )
> >
> > that link should be;
> >
> > http://lf.8k.com/TOOLS/TOOLS.HTM
>
> Because of the binary paranoia in this group, I have disassembled
>
[...]

> *********************** section 1 *************************
> 295b : 00000100 movem.w r0-r7,-(sp) (60)
[...]

I'm much happier with intel op codes. (IYBSK)

laura fairhead

unread,
Oct 31, 2001, 6:00:16 PM10/31/01
to

I gather that Herbert isn't very happy with intel op-codes and
maybe that is why he wrote his ASS486 thing; but also it lookz like
a nice assembler, supposedly it does disassembly too but all the
documentation is in German, and I can't read it very well at all.

Anyhow I had just written a commented disassembly so seeming as
it's come up... this is just the ascii-decoder part, the encode
program currently adds relocation code to the encoded program
which is section 3 in Herberts disassembly.

DB 60 ;PUSHA all registers saved. when the decoder has finished
; it jumps to the created data which will begin with
; the relocation code. The relocation code when done
; will issue a POPA to get all registers (minus FLAGS)
; back to as they were at the start of the DOS .COM
; then JMP 0x0100
DB 68 7D 61 ;PUSH 617D
DB 58 ;POP AX
DB 50 ;PUSH AX
DB 35 79 60 ;XOR AX,6079
DB 50 ;PUSH AX
DB 5D ;POP BP BP=104 this value is kept in BP throughout
DB 34 6E ;XOR AL,6E
DB 50 ;PUSH AX
DB 5F ;POP DI DI=16A =rstart, the end of the decoder body
; and the first byte of encoded data
DB 58 ;POP AX AX=617D is used to apply fixups below
DB 57 ;PUSH DI stack 016A. this is popped immediately
; on entry to the main loop into the SI register
; due to POP SI being 0x5E (a disallowed code)
; the instruction is created in the loop body
; at fixup *F7*
; apply fixups to decoder body, all these bytes could not
; be represented within the valid code set so have to be adjusted
; note the offsets are relative to 0104 in BP
SUB [BP+34],AL ;*F1*
SUB [BP+36],AL ;*F2*
SUB [BP+3D],AL ;*F3*
SUB [BP+46],AL ;*F4*
SUB [BP+48],AX ;*F5*
SUB [BP+4C],AL ;*F6*
SUB [BP+65],AL ;*F8*
SUB [BP+52],AL ;*F9*
XOR [BP+54],AL ;*F7*
DB 73 2A ;JNC K0 CF=0 due to XOR above so this branches always
; Apart from jumping to the main loop this branch
; also serves the purpose of forcing a flush of
; the prefetch queue so that all modified bytes
; will be seen by the processor. Pentium+ CPUs
; flush the prefetch queue any bytes within it
; are modified, automatically, however pre-Pentium
; CPUs do not.
;
; table for translating ascii codes back to base-85 value
; 0D of the line break is also the last element of the table
;:TAB = 012E
DB 7D 60 41 3F 2B 2C
DB 0D 0A ; CR,LF line break. end of 1st line of decoder ascii-code
;
; during the main loop registers are used-
; EDX=current dword data being made
; SI=read data pointer
; DI=write data pointer
; BP=0104 (used to get base offset to access table :TAB)
; EAX=each byte read is converted to a base-85 value in EAX
; CX=valid bytes left to read to complete building current dword in EDX
;
;:L2 = 0136
DB 66 6B 4F 55 ;IMUL EDX,EDX,55 fixup *F1* at 0138: 4F-7D=D2
;:L0 = 013A
DB 29 ;LODSB fixup *F2* at 013A: 29-7D=AC
;:L1 = 013B
; convert ascii value in AL to base-85 value
; increment AL once plus once for each 'hole' it lies below
; this will translate ascii values so that we have a contiguous
; sequence starting at 0x2A, for ascii 0x23.
DB 3A 47 2A ;CMP AL,[BX+2A] 0104+2A=012E =TAB data table
DB 40 ;INC AX
DB 43 ;INC BX
; = 0140
DB 72 76 ;JC L1 fixup *F3* at 0141: 76-7D=F9 (-07)
; de-biasing the value back to 0 based is done with a SUB and then
; a DEC so that the 0x23 ascii value can be picked up (by now it will
; be 0x2A) as well as having CF=1 for any values before 0x23
DB 2C 2A ;SUB AL,2A
DB 74 24 ;JZ rstart
DB 48 ;DEC AX
;:L3 = 0147
DB 55 ;PUSH BP
DB 5B ;POP BX BX=0104
; = 0149
; if the carry flag is set now from the SUB above the value was before
; the first code 0x24 (normally this will be 0x0D and 0x0A but in future
; will probably include 0x21 which may be used as a padding character)
; so ignore it.
DB 72 6C ;JC L0 fixup *F4* at 014A: 6C-7D=EF (-17)
; next base-85 chunk added to total dword, continue looping
; if more.
DB 66 7E 23 ;ADD EDX,EAX fixup *F5* at 014C: 237E-617D=C201
DB 49 ;DEC CX
DB 75 62 ;JNZ L2 fixup *F6* at 0150: 62-7D=E5 (-1B)
; = 0151
; write next decoded dword to store
DB 66 52 ;PUSH EDX
DB 66 58 ;POP EAX
DB 66 28 ;STOSD fixup *F9* at 0155: 28-7D=AB
DB 56 ;PUSH SI
; initial entry is here so that SI is initialised from the stack
; in subsequent loops the above PUSH cancels this instruction
;K0 = 0158
DB 23 ;POP SI fixup *F7* at 0158: 23^7D=5E
; set EAX=EDX=00000000 ready to create next dword
; set CX=6, bytes to read to make the base-85 value
; this is actually 5 but we jump back to the loop via L3
; so there is an extra decrement of the count
DB 66 6A 7D ;PUSHD 7D
DB 66 58 ;POP EAX
DB 34 7B ;XOR AL,7B EAX=00000006
DB 50 ;PUSH AX
DB 59 ;POP CX CX=0006
DB 24 40 ;AND AL,40 EAX=00000000
DB 66 50 ;PUSH EAX
DB 66 5A ;POP EDX EDX=00000000
; = 0168
; go back to loop at L0, but via L3 so that BX gets loaded properly
; on the very first loop. CF=0 from the AND instruction above so
; this branch always occurs.
DB 73 5A ;JNC L3 fixup *F8* at 0169: 5A-7D=DD (-23)
; = 016A
;:rstart
; encoded data starts here. when decoded the first byte will start here
; also so the decoder jumps here when finished (again the jump is
; important to ensure a prefetch queue flush)

byefrom

Herbert Kleebauer

unread,
Oct 31, 2001, 6:13:18 PM10/31/01
to

And I prefer Motorola 68000 code. But there was an error in my post:
not 6 but 5 ascii bytes are used to generate 4 binary bytes. This
code is optimized till the last byte. Great work.

Terry Newton

unread,
Oct 31, 2001, 10:45:38 PM10/31/01
to
laura_f...@my-deja.com (laura fairhead) wrote:

>>[snip] convert .COM file


>>to ascii-code using my CM3 utility ( http://lf.8k.com/TOOLS )
>
>that link should be;
>
>http://lf.8k.com/TOOLS/TOOLS.HTM

Far out! Thank you very much, seems to work great.
Now I can write just about anything I want a batch to do
(that real batch can't) in ASIC (an almost-basic compiler)
and convert the resulting com file to batch code. To automate
the process I made a ASIC2BAT batch that compiles the asic
code, runs CM3 then uses qbasic to append the source code
(prepending :: to each line) so I can tell what all the
ascii-bin stuff does. Way Cool!

Terry Newton

Remove "filter." to send email

Clueless in Seattle

unread,
Nov 1, 2001, 2:12:24 PM11/1/01
to
> Clueless in Seattle wrote in message

> > I'd like to add a routine to a batch file that would check the size of
> > a certain file, and then if the file is larger than 64 K, branch to
> > another routine.

That code works great! But I don't understand most of it.

Suppose I wanted to change the file so that it would check to see if a
file was larger than 70, 75 or 80 K; what would I need to change?

William Allen

unread,
Nov 1, 2001, 4:06:40 PM11/1/01
to
Clueless in Seattle wrote in message
...snip

> That code works great! But I don't understand most of it.

To understand it, you need to learn to use Debug, which
is one of the oldest and most powerful Batch commands.
The code uses the fact that 64K - the size you specified -
is particularly simple to check for.

Execellent and definitive Debug documentation is provided
in the Microsoft MS-DOS Enclyclopedia. Useful addtional
material is provided in PC Magazine DOS Power Tools,
which has a chapter on Debug. Those are the two main
references we use here.

--
William Allen


William Allen

unread,
Nov 1, 2001, 5:51:17 PM11/1/01
to
Clueless in Seattle wrote in message
...snip

> Suppose I wanted to change the file so that it would check to see if a
> file was larger than 70, 75 or 80 K; what would I need to change?

This variant of the original code loads the filesize in units
of 2Kbytes into the current ERRORLEVEL for files up
to 510Kbytes.

So, the condition
IF ERRORLEVEL x
is true for files larger than 2xKbytes for ERRORLEVEL to 255

Note that ERRORLEVELs are evaluated modulo 256, so values
above 255 are treated as their remainder on division by 256.

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (%1)==() GOTO USAGE
IF NOT EXIST %1 GOTO USAGE

ECHO.e100 89 da 89 c8 bb 0 8 f7 f3 b4 4c cd 21 c3>%TEMP%.\S
ECHO.g>>%TEMP%.\S
debug %1<%TEMP%.\S>NUL
DEL %TEMP%.\S
IF ERRORLEVEL 20 ECHO. File is larger than 40K
IF ERRORLEVEL 25 ECHO. File is larger than 50K
IF ERRORLEVEL 30 ECHO. File is larger than 60K
IF ERRORLEVEL 35 ECHO. File is larger than 70K
IF ERRORLEVEL 40 ECHO. File is larger than 80K
:: And so on for any ERRORLEVEL to 255 = 510K

GOTO EOF
:USAGE
ECHO. Usage %0 Filespec

ECHO. Returns ERRORLEVEL=filesize in steps of 2Kbytes
ECHO.

:EOF

====End cut-and-paste (omit this line)
To use the code above, cut-and-paste the text between the ==== lines
into a file with extension .BAT and base name of your choice. Lines
that don't begin with two spaces have wrapped in transmission. The
code was created and tested in Win9x GUI.

--
William Allen


laura fairhead

unread,
Nov 1, 2001, 10:54:56 PM11/1/01
to
On Wed, 31 Oct 2001 05:22:13 GMT, laura_f...@my-deja.com (laura fairhead) wrote:

This can be done though. SORT almost will do a numeric comparison
but the numbers need to be in fixed fields. See my post in the
thread;
'Count the number of characters in a variable'
for details of a method using CHOICE that allows you to find
the length of a string, this can be used to pad strings to fixed
field widths and consequently enable you to do numeric comparisons
with SORT.

The batch uses a new filesize utility which returns the extact
file size (up to 2Gb only though) as text which when run as
a batch file sets the variable named in the first parameter
with the size in bytes.

This implementation the invocation is;

SIZECHK filename

And it prints whether the size is less-than, equal-to or greater-than
the preset amount (at the head of the listing this is variable %SIZE%)

~~~~~~~~~~~~~~~~~~~~~~~SIZECHK.BAT~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ECHO OFF
::
IF !%1==!. %2
::
:: initialise. SIZE may be changed here for different comparisons
:: or taken from command line
SET SIZE=65536
SET FILE=%1
SET FILESIZE=%TEMP%.\@TMP0.COM
SET TMP0=%TEMP%.\@TMP0.BAT
::
:: %BEL% is ascii 0x07
ECHO +,|CHOICE /C, /N SET BEL=>%TMP0%
CALL %TMP0%
FOR %%_ IN (%BEL%) DO SET BEL=%%_
::
:: create utility program to find file sizes
ECHO:`h}aXP5y`P]4nP_XW(F4(F6(F=(FF)FH(FL(Fe(FR0FTs*}`A?+,>%FILESIZE%
ECHO:fkOU):G*@Crv,*t$HU[rlf~#IubfRfXf(V#fj}fX4{PY$@fPfZsZ$:K\>>%FILESIZE%
ECHO:F$/HGjA])sEf/6h*9RQV;9Z{9JAH?qA9RY0tdNSDr=(8~0W@Q8U6PB4X>>%FILESIZE%
ECHO:0rOM{DJ}I2bmP@QI(~p@xSgq51H,rME9oiobv[`X:xDQZBwH@U1x;4\F>>%FILESIZE%
ECHO:;pbot$fJb$$/)X#>>%FILESIZE%
::
:: get size of file %FILE% into variable %F%
%FILESIZE% %FILE% >%TMP0%
CALL %TMP0% F
::
:: ------------ compare values %F% and %SIZE% and output result -----
CALL %0 . GOTO:PAD11 F %F%
CALL %0 . GOTO:PAD11 SIZE %SIZE%
::
IF %F%==%SIZE% ECHO %FILE% IS EXACTLY %SIZE% BYTES LONG
IF %F%==%SIZE% GOTO SK
ECHO %F%>%TMP0%
ECHO %SIZE%>>%TMP0%
FIND /V /N "" <%TMP0% |SORT /+4 |FIND /V /N ""|FIND "[1][1]">NUL
IF NOT ERRORLEVEL 1 ECHO %FILE% IS LESS THAN %SIZE% BYTES LONG
IF ERRORLEVEL 1 ECHO %FILE% IS GREATER THAN %SIZE% BYTES LONG
:SK
::
:: clean-up and exit program
FOR %%_ IN (%TMP0% %FILESIZE%) DO IF EXIST DEL %%_
FOR %%_ IN (FILESIZE TMP0 BEL F _ FILE @0 @1) DO SET %%_=
GOTO OUT
::
:PAD11
:: routine to pad number %4 to 11 characters long, return in variable name %3
SET @0=%4
ECHO:%@0%%BEL%|CHOICE /C%BEL% /N SET @1=>%TMP0%
CALL %TMP0%
:L
SET @0=0%@0%
SET @1=%BEL%%@1%
IF NOT %@1%==%BEL%%BEL%%BEL%%BEL%%BEL%%BEL%%BEL%%BEL%%BEL%%BEL%%BEL%%BEL% GOTO L
SET %3=%@0%
::
:OUT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
complete source code for FILESIZE.COM utility
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


OPTION SCOPED
OPTION SEGMENT:USE16
.486

cseg SEGMENT BYTE

ASSUME NOTHING
ORG 0100h

kode PROC NEAR

MOV AH,9;MOV DX,OFFSET t0;INT 021h ;; output 'SET %1='
MOV SI,081h ;; parsing command line
lop: ;; skip whitespace


LODSB
CMP AL,020h;JZ lop
CMP AL,9;JZ lop
DEC SI

MOV DX,SI ;; DX=start of filename
lop1: ;; skip to end of filename
LODSB
CMP AL,021h;JNC lop1
MOV AX,03D00h ;; open file
MOV [SI-1],AL
INT 021h
XCHG BX,AX
MOV AX,04202h ;; set file pointer to EOF
XOR CX,CX;CWD
INT 021h ;; DX:AX returns position
PUSH DX
PUSH AX ;; get position (=size) into EAX
POP EAX
XOR EBX,EBX;MOV BL,0Ah
XOR CX,CX
lop2: ;; put decimal expansion on stack
XOR EDX,EDX;DIV EBX;PUSH DX
AND EAX,EAX;LOOPNZ lop2
lop3: ;; print decimal expansion
POP DX;OR DL,030h;MOV AH,2;INT 021h
INC CX;JNZ lop3
RET

t0:
DB "SET %1=$"

kode ENDP

cseg ENDS

END FAR PTR kode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


To assemble first translate ;; -> ; and ; -> \n
Assemble .COM file using MASM6+ and convert .COM file

to ascii-code using my CM3 utility ( http://lf.8k.com/TOOLS/TOOLS.HTM


eg-
SED "s/;;/\x01/g;s/;/\n/g;s/\x01/;/g" FILENAME >FILENAME.ASM
MASM FILENAME;
LINK /T FILENAME;
CM3 FILENAME.COM >BATCH.BAT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

nightnight

Aleksey D. Tetyorko

unread,
Nov 2, 2001, 8:35:24 AM11/2/01
to
Hi!
Here is my version of debug using.
::===================================================
@echo off
:: filesze.bat - Tests, if the size of the file given is greater than
:: 64K. Uses DEBUG!
:: Make DEBUG script.
echo a>$$$$$$.dbs
echo mov ax,3d00>>$$$$$$.dbs
echo mov dx,123>>$$$$$$.dbs
echo int 21>>$$$$$$.dbs
echo jc 11f>>$$$$$$.dbs
echo mov bx,ax>>$$$$$$.dbs
echo mov ax,4202>>$$$$$$.dbs
echo xor cx,cx>>$$$$$$.dbs
echo xor dx,dx>>$$$$$$.dbs
echo int 21>>$$$$$$.dbs
echo jc 11f>>$$$$$$.dbs
echo xor ax,ax>>$$$$$$.dbs
echo or dx,dx>>$$$$$$.dbs
echo jz 11f>>$$$$$$.dbs
echo mov al,ff>>$$$$$$.dbs
echo mov ah,4c>>$$$$$$.dbs
echo int 21>>$$$$$$.dbs
echo db '%1',0>>$$$$$$.dbs
echo.>>$$$$$$.dbs
echo g=100>>$$$$$$.dbs
:: Run it
<$$$$$$.dbs debug >nul
:: Test the error code
if errorlevel 255 goto :big
if errorlevel 1 goto :error
echo %0 -- file '%1' - exists and is less than 64K!
goto :end

:big
echo %0 -- file '%1' - exists, but is not less than 64K!
goto :end

:error
echo %0 -- error, maybe, file '%1' does not exist!
:end
if exist $$$$$$.dbs del $$$$$$.dbs
::=============================================
Usage: filesze file
It was tested at W95, W98.
Aleksey

Outsider

unread,
Nov 1, 2001, 8:48:38 AM11/1/01
to
Aleksey D. Tetyorko wrote:
>
> Hi!
> Here is my version of debug using.
> ::===================================================
> @echo off
> :: filesze.bat - Tests, if the size of the file given is greater than
> :: 64K. Uses DEBUG!

[snipped]

Works great here :). It just needs an option to specify the bytes sought
as a parameter, ie. "filesze 131072". Another option might _possibly_ be
to report if the file is the exact size specified. This could be used in
cases where a non matching file size signifies a corrupt file, wrong
version. etc.

--
<!-Outsider//->
MS-DOS 6.22, Windows for Workgroups 3.11, Netscape Communicator 4.08

It is better to weep with wise men than laugh with fools.

Herbert Kleebauer

unread,
Nov 2, 2001, 11:19:27 AM11/2/01
to

"Aleksey D. Tetyorko" wrote:
>
> Hi!
> Here is my version of debug using.
> ::===================================================
> @echo off
> :: filesze.bat - Tests, if the size of the file given is greater than
> :: 64K. Uses DEBUG!
> :: Make DEBUG script.
> echo a>$$$$$$.dbs
> echo mov ax,3d00>>$$$$$$.dbs
> echo mov dx,123>>$$$$$$.dbs
> echo int 21>>$$$$$$.dbs

> echo db '%1',0>>$$$$$$.dbs

The problem is, that function 3d understands only short 8+3
filenames. If you use stdin, you have also long filename
support. But then you can't run the program within debug.

Outsider

unread,
Nov 1, 2001, 11:51:40 AM11/1/01
to

Catch-22

William Allen

unread,
Nov 2, 2001, 12:01:05 PM11/2/01
to
William Allen wrote in message
...snip
> This variant of the original code loads the filesize in units
> of 2Kbytes into the current ERRORLEVEL for files up
> to 510Kbytes.

These two variants use ExitPrompt to avoid the need to
create a debug script file. The first returns ERRORLEVEL
equal to filesize in 2Kbyte units to 510Kbytes and the
second returns ERRORLEVEL equal to filesize in 1Kbyte
units to 255Kbytes.

====Begin cut-and-paste (omit this line)
@ECHO OFF

:: Return ERRORLEVEL=filesize in 2Kbyte units (to 510Kbytes)


IF (%1)==() GOTO USAGE
IF NOT EXIST %1 GOTO USAGE

ECHO.EXIT|%COMSPEC%/kPrompt e100 89 da 89 c8 bb 0 8 f7 f3 b4 4c cd 21 c3$_g$_|debug %1>NUL

:: Demo lines
IF ERRORLEVEL 20 ECHO. File is larger than or equal to 40K
IF ERRORLEVEL 25 ECHO. File is larger than or equal to 50K
IF ERRORLEVEL 30 ECHO. File is larger than or equal to 60K
IF ERRORLEVEL 35 ECHO. File is larger than or equal to 70K
IF ERRORLEVEL 40 ECHO. File is larger than or equal to 80K


:: And so on for any ERRORLEVEL to 255 = 510K

GOTO EOF
:USAGE
ECHO. Usage %0 Filespec
ECHO. Returns ERRORLEVEL=filesize in steps of 2Kbytes
ECHO.

:EOF

====End cut-and-paste (omit this line)
To use the code above, cut-and-paste the text between the ==== lines
into a file with extension .BAT and base name of your choice. Lines
that don't begin with two spaces have wrapped in transmission. The

Batch code is intended for use in the Win9x GUI, where it was tested.

====Begin cut-and-paste (omit this line)
@ECHO OFF

:: Return ERRORLEVEL=filesize in 1Kbyte units (to 255Kbytes)


IF (%1)==() GOTO USAGE
IF NOT EXIST %1 GOTO USAGE

ECHO.EXIT|%COMSPEC%/kPrompt e100 89 da 89 c8 bb 0 4 f7 f3 b4 4c cd 21 c3$_g$_|debug %1>NUL

:: Demo lines
IF ERRORLEVEL 30 ECHO. File is larger than or equal to 30K
IF ERRORLEVEL 35 ECHO. File is larger than or equal to 35K
IF ERRORLEVEL 40 ECHO. File is larger than or equal to 40K
IF ERRORLEVEL 45 ECHO. File is larger than or equal to 45K
IF ERRORLEVEL 50 ECHO. File is larger than or equal to 50K
:: And so on for any ERRORLEVEL to 255 = 255K

GOTO EOF
:USAGE
ECHO. Usage %0 Filespec
ECHO. Returns ERRORLEVEL=filesize in steps of 2Kbytes
ECHO.

:EOF

====End cut-and-paste (omit this line)
To use the code above, cut-and-paste the text between the ==== lines
into a file with extension .BAT and base name of your choice. Lines
that don't begin with two spaces have wrapped in transmission. The

Batch code is intended for use in the Win9x GUI, where it was tested.

--
William Allen

Explanation and examples of the ExitPrompt technique
From: "William Allen"
Newsgroups: alt.msdos.batch
Subject: ECHOing custom prompt messages [LONG]
Date: Sun, 7 Oct 2001 11:01:23 +0100
Message-ID: <9pp97l$jfrjf$1...@ID-55970.news.dfncis.de>

You can read old Usenet posts at:
http://groups.google.com/advanced_group_search

Note: Google search by Message-ID is usually the quickest.
The Message-ID is the identifier in the <angle> brackets.
Simply cut-and-paste the Message-ID into Google page above.


Clueless in Seattle

unread,
Nov 3, 2001, 11:28:13 AM11/3/01
to

William Allen wrote:

> This variant of the original code loads the filesize in units
> of 2Kbytes into the current ERRORLEVEL for files up
> to 510Kbytes.
>
> So, the condition
> IF ERRORLEVEL x
> is true for files larger than 2xKbytes for ERRORLEVEL to 255
>
> Note that ERRORLEVELs are evaluated modulo 256, so values
> above 255 are treated as their remainder on division by 256.

Whew! I have a long way to go before I understand a tenth of what you
guys post here. So I think I'd better do some homework before I ask
anymore questions in this thread.

So, thanks for your willingness to help. I regret that I haven't
learned enough to participate intelligently, but if I'm hoping that if
I keep at it I'll eventually get a handle on this stuff.

Thanks again.

Charles Dye

unread,
Nov 3, 2001, 4:55:34 PM11/3/01
to
On Tue, 30 Oct 2001 12:58:20 -0800, Clueless in Seattle
<spamless_...@yahoo.com> wrote:

>I'd like to add a routine to a batch file that would check the size of
>a certain file, and then if the file is larger than 64 K, branch to
>another routine.
>
>So I guess I'm asking two questions:
>
> 1. Is it possible for a batch file to check the size of a
>file?

Okay -- I can't stand it anymore. Here is how I would accomplish the
above, in two lines and using straightforward, readable syntax, using
one freeware utility.

locate c:\download\testfile.bin /s:64k /nr > nul
if not errorlevel 1 goto foundit

LOCATE is my freeware file-finder; download through the link below.
TESTFILE.BIN is the name of the file to find; normally you would use
wildcards to search for more than one match, but here I am specifying
the exact name to look for. C:\DOWNLOAD\ is the location to search;
the default behavior is to search entire drives, or (with /NR) the
current directory. /S:64K is the range of file sizes to accept, in
bytes, kilobytes (with the trailing K) or megabytes (with an M.)
/S:100,200 would match files of 100 to 200 bytes; /S:,1M would
match files of one megabyte or less (note the comma before the 1M.)
The /NR prevents recursion into subdirectories, so C:\DOWNLOAD\FOO\,
C:\DOWNLOAD\HORST\ and so on will not be searched. The > NUL
prevents Locate's messages from being displayed on the screen;
you should probably omit it while experimenting with this utility.

Locate returns errorlevel 0 if one or more matching items were found,
1 if no matching items were found, or 2 or greater for various errors.
The second line therefore branches to a label FOUNDIT if the file
C:\DOWNLOAD\TESTFILE.BIN exists, and if it is 64K or larger in size.

One small difference between what you asked for and what I wrote:
you wanted to check for a file size of _more than_ 64K, while I'm
checking for a file size _greater than or equal to_ 64K. If you do
need to exclude a file size of exactly 64K, write the size range in
bytes instead:

locate c:\download\testfile.bin /s:65537 /nr

> 2. If so, can the size checking routine be written so as to
>return different values, depending on the the size of the file being
>checked?

Locate's return code (errorlevel) is just a simple, yes-or-no thing.
To check for more than one range would require multiple invocations
of the program:

locate c:\download\testfile.bin /s:10m /nr > nul
if not errorlevel 1 goto huge
locate c:\download\testfile.bin /s:100k /nr > nul
if not errorlevel 1 goto large
locate c:\download\testfile.bin /s:1k /nr > nul
if not errorlevel 1 goto medium
locate c:\download\testfile.bin /s:1 /nr > nul
if not errorlevel 1 goto small
locate c:\download\testfile.bin /0 /nr > nul
if not errorlevel 1 goto empty
rem * code continues here if file c:\download\testfile.bin
rem * does not exist at all....

The /0 in line 9 is just a synonym for /S:0,0 or /S,0

If you're interested in Locate, you can pick a copy from my homepage:

http://www.highfiber.com/~raster/freeware.htm

DOS archives like Garbo, Simtel, SAC, etc. have older (but still
quite capable) versions as well. Alternatively, other DOS file-
finder utilities like HUNT or Target can probably be used to
accomplish the same task.

--
Charles Dye ras...@highfiber.com


Rik D'haveloose

unread,
Nov 4, 2001, 9:41:05 AM11/4/01
to
William Allen wrote
> Clueless in Seattle wrote

> ...snip
> > That code works great! But I don't understand most of it.
>
> To understand it, you need to learn to use Debug, which
> is one of the oldest and most powerful Batch commands.
==8<

??? LOL

IMHO, originally debug is some external prog which enables some
(minimal) 16-bit-assembler programming, and can be (mis)used in batching
(but is not strictly speaking a batch command....)

KISS


Charles Dye

unread,
Nov 6, 2001, 7:31:04 PM11/6/01
to
"Rik D'haveloose" <brol.d...@xs4all.be> wrote in message news:<9s9e85$sk6$1...@news1.xs4all.nl>...
> William Allen wrote

> >
> > To understand it, you need to learn to use Debug, which
> > is one of the oldest and most powerful Batch commands.
>
> IMHO, originally debug is some external prog which enables some
> (minimal) 16-bit-assembler programming, and can be (mis)used in batching
> (but is not strictly speaking a batch command....)

Sure it is. Like EDLIN, QBASIC, and many others, DEBUG can be used
either interactively or in batch mode.

--
Charles Dye ras...@highfiber.com

Rik D'haveloose

unread,
Nov 8, 2001, 5:16:31 PM11/8/01
to
Charles Dye wrote
> Rik D'haveloose wrote

> > IMHO, originally debug is some external prog which enables some
> > (minimal) 16-bit-assembler programming, and can be (mis)used in
batching
> > (but is not strictly speaking a batch command....)
>
> Sure it is. Like EDLIN, QBASIC, and many others, DEBUG can be used
> either interactively or in batch mode.

please reread carefully my remark, and do not give it some 'suspected'
meaning.
(and as far as there is some agreed, official definition of batch
commands, almost the same as for OS-definition :-)

KISS


0 new messages