1.

Solve : File size limit !??

Answer»

Hello

I'm managed to finalize a batch file that checks the filesize of a database and when it reaches more than 4 GB the batch program moves the database elsewhere. (I'm doing this periodic check with Windows Scheduler)

This is my code:
---------------------------------------
@echo off
for %%a in (dir "c:\Data\database.mdf") do if %%~za GEQ 4000000000 start /max move.bat else exit

--------------------------------------

THE PROBLEM:
Instead of moving the database when it reaches 4GB or more the program moves it when database has only 2GB or 2.1, 2.2GB.
I don't know why. I tried also with GTR instead of GEQ and also I changed the 4GB limit to 3.9GB(3900000000) but no change. I've got no CLUE why is doing this.
Oh ... and I checked also to have a NTFS partition and I have it.

Anybody know what I'm doing wrong? Is there a limitation in DOS for reading 4GB?
How can I solve this. It's a very INTERESTING program that I'm developing, I will provide it to you when it's fully opperational.

Thank you in advance
NT batch arithmetic has maximum precision of 32 bits, so the greatest number it can hold is + or - 2,147,483,648. That number of bytes is 2 gigabytes. The condition in your IF test is "satisfied" because of arithmetic overflow. You will have to think of another solution using a different programming language.

PS It's not "DOS".



Thank you "contrex"

Is there a way to get file size in SQL and start a program when it has 4GB?

Can I do something like this (a trick)

@echo off
for %%a in (dir "c:\Data\database.mdf") do if %%~za ***** GEQ 4000000000 start /max move.bat else exit

instead of ***** ... can I divide that value like %%za / 1024[size in kB] and then compare GEQ 3906250kb ?

Is that posible? ... I don't know with command is for that (i read about SET)
Anybody knows how to solve this problem in any way?

Thank you!You cannot do that because the very act of trying to perform the arithmetic operation (%%~za / 1024) will cause overflow if %%za EVALUATES to more than 2 147 483 648.
What you could do is divide by 1000, by stripping off the right-hand 3 digits using string manipulation, then do your numerical calculation on the result

GrahamContrex, you're so leet...

Quote

contrex
Leet
******
Online Online

Posts: leet


View Profile
Quote from: DeltaSlaya on August 13, 2007, 03:03:23 AM
Contrex, you're so leet...

[edit] Duh - I see now! What happened to "mentor"

Anyway, it's 2337 anyway, not ell ee ee tee. (I mean, come on GUYS!)




Yea lol your rank is literally 'leet' and your post count was too. Not your advice lol. I wasn't aware you could do logical comparisons like that in strings.I have seen both "1" and "2" used for "L" in 1337 speak... which to use maybe I should start a thread.

As for the strings I found a mistake, it doesn't work properly.

Thank you "contrex"

The code was very helpfull ... I developed a sql statement that does the same thing like your code and I put them to test ... in a couple of days I will see the results.

Thank you very much

PS : What means "leet" ... it comes from "elitte"? I didn't understand last 3-4 posts
Quote from: victor.marincus on August 13, 2007, 04:00:06 AM
PS : What means "leet" ... it comes from "elitte"?

yeah.
http://en.wikipedia.org/wiki/LeetHere's one way to do the number-as-string thing

Quote


@echo off
setlocal enabledelayedexpansion

Set /P filesize=Filesize? %

set sizelimit=4000000000

set v1=%filesize%
set v2=%sizelimit%

REM find string lengths
REM echo string to temp file
REM escape 1st char with a caret in case it's a 1 or 2
REM which mucks up echo redirection, then
REM read file bytes & subtract 2 for CR & LF

echo ^%v1%> "%temp%\v1.txt" & for %%A in (%temp%\v1.txt) do set len1=%%~zA & set /a len1 -=2
echo ^%v2%> "%temp%\v2.txt" & for %%A in (%temp%\v2.txt) do set len2=%%~zA & set /a len2 -=2

REM compare string lengths and if they differ,
REM add leading zeroes to the shorter one
REM until it equals the other in length

if %len1% GTR %len2% (
set ss=%v2%
set /a padlen=%len1% & set /a padlen-=%len2%
FOR /L %%z IN (1,1,%padlen%) DO set ss=0!ss!
set v2=%ss% & goto end
)

if %len1% EQU %len2% goto end

if %len1% LSS %len2% (
set ss=%v1%
set /a padlen=%len2% & set /a padlen-=%len1%
FOR /L %%z IN (1,1,%padlen%) DO set ss=0!ss!
set v1=%ss% & goto end
)

:end

REM do string comparison

if "%v1%" GEQ "%v2%" echo %filesize% is ^>= limit
if "%v1%" LSS "%v2%" echo %filesize% is ^< limit
Thank you contrex for the code ... I made few adjustments hope others need this ...

@echo off
setlocal enabledelayedexpansion
for %%a in (dir "c:\Data\Data.mdf") do set filesize=%%~za

set sizelimit=4000000000

set v1=%filesize%
set v2=%sizelimit%

REM find string lengths
REM echo string to temp file
REM escape 1st char with a caret in case it's a 1 or 2
REM which mucks up echo redirection, then
REM read file bytes & subtract 2 for CR & LF

echo ^%v1%> "%temp%\v1.txt" & for %%A in (%temp%\v1.txt) do set len1=%%~zA & set /a len1 -=2
echo ^%v2%> "%temp%\v2.txt" & for %%A in (%temp%\v2.txt) do set len2=%%~zA & set /a len2 -=2

REM compare string lengths and if they differ,
REM add leading zeroes to the shorter one
REM until it equals the other in length

if %len1% GTR %len2% (
set ss=%v2%
set /a padlen=%len1% & set /a padlen-=%len2%
FOR /L %%z IN (1,1,%padlen%) DO set ss=0!ss!
set v2=%ss% & goto end
)

if %len1% EQU %len2% goto end

if %len1% LSS %len2% (
set ss=%v1%
set /a padlen=%len2% & set /a padlen-=%len1%
FOR /L %%z IN (1,1,%padlen%) DO set ss=0!ss!
set v1=%ss% & goto end
)
:end

REM do string comparison

if "%v1%" GEQ "%v2%" (
echo %filesize% is ^>= limit %sizelimit%
start /max backup.bat
)

if "%v1%" LSS "%v2%" (
echo %filesize% is ^< limit %sizelimit%
exit
)
-------------------------------
Make sure, in line 3 ---for %%a in (dir "c:\Data\Data.mdf") do set filesize=%%~za---
NOT TO leave any spaces after ---=%%~za--- it will ruin the test. It took me a wile to figure it out. I forgot one space after and the comparison was always wrong(4Gb v.s. 40G in length). Now it's working well. Be carefull not to make mistakes like me.

Thank you again contrex, you are the best...

P.S. SQL sucks ... never managed to run a batch file from within .sql script file.



Discussion

No Comment Found