Computing.Net > Forums > Windows XP > checking size of file from batch

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

checking size of file from batch

Reply to Message Icon

Name: damiike
Date: February 25, 2007 at 20:19:54 Pacific
OS: WinXP/2K/NT/Server03
CPU/Ram: 512
Product: custom
Comment:

Hi, I need some help please.

I need to create a batch file in which i am going to have scheduled. I am unsure on which OS it will be running on, but will be 1 of the following: XP, NT, 2000, Server 2003.

I am looking for a way in batch that I can check the size of a file, if it is greater than 500mb, i will perform a loop.

I am having trouble with working out how to get the file size and check if it is greater than 500mb.

Any help on how to perform this command is greately appreciated.

Cheers,

damiike



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: February 26, 2007 at 03:18:04 Pacific
Reply:

To check the file size you need to assign the file name to an external or internal variable and then use the ~z modifier, e.g. %~z1.

Then to chek the size use an If statement

If %~z1 gtr 524288000 GoTo :SomeLabel

What above posted works in all NT based systems i.e. the ones you referred as candidate environments (but NOT under Win 9X/ME).

If the file name is on the command tail, it is assigned to a variable without problems, if however you catch the file name inside the script to setup an internal variable use an internal subroutine

Call :SomeLabel FileName

and code the routine as below at the bottom of your script

GoTo :EOF
:SomeLabel
......
.....
GoTo :EOF



0

Response Number 2
Name: damiike
Date: February 26, 2007 at 19:15:22 Pacific
Reply:

Thanks for the help IVO,
i've attempted the following, here is my code, still struggling to get the size if statement to work, the following is my code/errors im getting:

code:

echo on
set 1 =C:\test.txt

If %~z1 GTR 524288000 GoTo :action

echo off

rem selects all time / date information for setting datestamp / timestamp details
:action
For /f "tokens=1-8 delims=:/-,. " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
set dow=%%i
set %%a=%%j
set %%b=%%k
set %%c=%%l
set hh=%%m
set min=%%n
set ss=%%o
set cs=%%p
)
)

rem set variables to datetime/timestamp needed.
SET DATESTAMP=%yy%%mm%%dd%
SET TIMESTAMP=%hh%%min%
----

error:

C:\Documents and Settings\maubor\Desktop\Seal>echo on

C:\Documents and Settings\maubor\Desktop\Seal>set 1 =C:\plossys3.cfg
524288000 was unexpected at this time.
C:\Documents and Settings\maubor\Desktop\Seal>If GTR 524288000 GoTo :action
C:\Documents and Settings\maubor\Desktop\Seal>

-----------

as you can see, the C:\test.txt variable never is questioned in the if statement, and the size condition does not test if the file is greater than the 500mb, all the other code is working correctly.

I appreciate your time and effort in helping me with this.

Cheers,

damiike


0

Response Number 3
Name: IVO
Date: February 27, 2007 at 03:02:53 Pacific
Reply:

Start your code as below

@Echo Off

For %%I in (C:\test.txt) Do If %%~zI gtr 524288000 GoTo :action

Rem selects all time / date information for setting datestamp / timestamp details

:action

where the For %%I statement (that fits just one row starting with For and ending with :action) is a trick to assign the file name to an internal variable (%%I) that is an item different from an environment variable as the operand of a Set statement. Environment variables can't be manipulated by variable's modifiers.

Sorry my raw english confused you as I tried to point out this issue.

As you need more support contact me by e-mail as this thread is fading out.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: checking size of file from batch

Update set of files using batch file www.computing.net/answers/windows-xp/update-set-of-files-using-batch-file-/180184.html

slow file transfer on the network www.computing.net/answers/windows-xp/slow-file-transfer-on-the-network/69356.html

run reg file from batch file www.computing.net/answers/windows-xp/run-reg-file-from-batch-file/133237.html