%~z1 Problems

B

Bell,Nathan

All,

I am writing a cmd script and as a part of it I want it to check a file
size and do a zip+split if larger than a certain size (3.8GB) otherwise do
just a zip. When I try to store the filesize variable on anything that is a
large file i.e: 3.8GB I get an "Invalid number, numbers must be less than
32bits of precision" error, which to me means that the number is too big but
I don't see how I can convert it to something smaller. I tried dividing it
first (to get MB instead of bytes, but that did not work either. Can anyone
assist? Here is the script:

@echo off
REM %1 = path to filename (source)
REM %2 = zip file name (target)
REM %3 = zip split filename (target)
REM %4 = password for zip file
SET/a filesize=%~z1
REM echo %filesize% MB
REM pause

U:
CD\mssql$b\backup\dbextraction
IF %filesize% GTR 4101253364 (goto:zipsplit) else (goto:zip)

goto:eof


:zipsplit
echo ***ZIPSplittingfile***
wzzip -s%4 %2 %1
wzzip -ys3984589 %2 %3
pause
goto:eof
:zip
echo ***Zippingfile***
wzzip -s%4 %2 %1
pause
goto:eof
 
B

billious

Bell said:
All,

I am writing a cmd script and as a part of it I want it to check a file
size and do a zip+split if larger than a certain size (3.8GB) otherwise do
just a zip. When I try to store the filesize variable on anything that is
a large file i.e: 3.8GB I get an "Invalid number, numbers must be less
than 32bits of precision" error, which to me means that the number is too
big but I don't see how I can convert it to something smaller. I tried
dividing it first (to get MB instead of bytes, but that did not work
either. Can anyone assist? Here is the script:

@echo off
REM %1 = path to filename (source)
REM %2 = zip file name (target)
REM %3 = zip split filename (target)
REM %4 = password for zip file
SET/a filesize=%~z1
REM echo %filesize% MB
REM pause

U:
CD\mssql$b\backup\dbextraction
IF %filesize% GTR 4101253364 (goto:zipsplit) else (goto:zip)

goto:eof


:zipsplit
echo ***ZIPSplittingfile***
wzzip -s%4 %2 %1
wzzip -ys3984589 %2 %3
pause
goto:eof
:zip
echo ***Zippingfile***
wzzip -s%4 %2 %1
pause
goto:eof

sure.

treat the filesize as a character-string and remove the last 3 characters,
making the result trunc(size/1000)

Under XP, this can be accomplished by

set filesize=%~z1
set filesize=%filesize:~0,-3%

but I'm not sure whether the "-" syntax is supported in W2K - nevertheless,
since the string is numeric by definition, lopping off the final 3
characters will leave a numeric result which I believe should be in the
required range (no need for the /a on the set)

If you're going to be really, really picky about the size, split the %~z1
STRING (and it's a string of characters[0..9]) into two separate variables
and play with them.

If 2K doesn't support the "-" syntax, then you might be able to get away
with splitting the size:

set filesize=%~z1
set filesizemsb=%filesize:~0,3%
set filesize=%filesize:~3%

which should place the first 3 chars of the size into filesizemsb and the
remainder into filesize. Your job to figure it out from there...

Tips & tricks in alt.msdos.batch.nt

set /?

from the prompt for SET docco - but fundamentally, it's a STRING
manipulation which MAY be used in arithmetic mode by specifying /A
 
A

Al Dunbar

Bell said:
All,

I am writing a cmd script and as a part of it I want it to check a file
size and do a zip+split if larger than a certain size (3.8GB) otherwise do
just a zip. When I try to store the filesize variable on anything that is
a large file i.e: 3.8GB I get an "Invalid number, numbers must be less
than 32bits of precision" error, which to me means that the number is too
big but I don't see how I can convert it to something smaller. I tried
dividing it first (to get MB instead of bytes, but that did not work
either. Can anyone assist? Here is the script:

@echo off
REM %1 = path to filename (source)
REM %2 = zip file name (target)
REM %3 = zip split filename (target)
REM %4 = password for zip file
SET/a filesize=%~z1
REM echo %filesize% MB
REM pause

U:
CD\mssql$b\backup\dbextraction
IF %filesize% GTR 4101253364 (goto:zipsplit) else (goto:zip)

goto:eof


:zipsplit
echo ***ZIPSplittingfile***
wzzip -s%4 %2 %1
wzzip -ys3984589 %2 %3
pause
goto:eof
:zip
echo ***Zippingfile***
wzzip -s%4 %2 %1
pause
goto:eof

You could try just truncating the last three digits of the size to give you
an approximate value in KB rather than bytes, perhaps something like this:

SET/a filesize=%~z1
set filesize=++++++++++++++++++++%filesize%
set filesize=%filesize:~-20%
set filesize=%filesize:~0,17%
set filesize=%filesize:+=%

This would be an approximation, of course. You could get a bit closer by
converting this KB value to MB by dividing it by 1049.

/Al
 
F

foxidrive

I am writing a cmd script and as a part of it I want it to check a file
size and do a zip+split if larger than a certain size (3.8GB) otherwise do
just a zip. When I try to store the filesize variable on anything that is a
large file i.e: 3.8GB I get an "Invalid number, numbers must be less than
32bits of precision" error, which to me means that the number is too big but
I don't see how I can convert it to something smaller. I tried dividing it
first (to get MB instead of bytes, but that did not work either. Can anyone
assist? Here is the script:

@echo off
REM %1 = path to filename (source)
REM %2 = zip file name (target)
REM %3 = zip split filename (target)
REM %4 = password for zip file
SET/a filesize=%~z1
REM echo %filesize% MB
REM pause

U:
CD\mssql$b\backup\dbextraction
IF %filesize% GTR 4101253364 (goto:zipsplit) else (goto:zip)

goto:eof


:zipsplit
echo ***ZIPSplittingfile***
wzzip -s%4 %2 %1
wzzip -ys3984589 %2 %3
pause
goto:eof
:zip
echo ***Zippingfile***
wzzip -s%4 %2 %1
pause
goto:eof

See if this gives you an idea:

@echo off
SET filesize=%~z1
echo %filesize%
set filesize=%filesize:~0,-3%
echo %filesize%
set filesize=%filesize:~0,-3%
echo %filesize%
pause
IF %filesize% GTR 4101 (goto:zipsplit) else (goto:zip)
 
B

billious

Jean Pierre Daviau said:
Peaking in:

What is the meaning of this:? %~z1
set filesize=%~z1

The size of the file, the name of which is provided as the first argument.

The ~ modifiers are documented under FOR/? (naturally...) but work with SET
.... paramref
 
M

Matthias Tacke

billious said:
The ~ modifiers are documented under FOR/? (naturally...) but work with SET
... paramref
Well, I think that should read:
but work with call ... paramref

They are also explained in "call /?"

The :~ commands in variables explained in "set /?" are for substring
handling (but do also work outside set statements)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top