Batch File NAme calling!

March 20, 2009 at 03:15:39
Specs: Windows XP
I am trying to use a batch file to check a file size.

I have found if %~z1 GTR 5000 pause

But I can't get it to work in my context.

I create a file \forums\testsize.jpg

I then tried to test its size (go figure) by

if %~z\forums\testsize.jpg GTR 10000 pause.

I have tried every combination of % " etc at either and both ends.

I have tried sending the filename to another batch file. and using %~z1

But it will only work if I actually drop a file onto the batch file.

Can anyone tell meif and how I can use %~z to check the file?

Thanks for any help

Nick


See More: Batch File NAme calling!

Report •


#1
March 20, 2009 at 04:02:13
For %~zx to work the variable must either contain a filename of a file that is in a current directory or a full path.

If you want to tack a path together you can run it through a for loop to get the file size:

set drive=c:
set dir1=\test\
set dir2=directory\
set file=testsize.jpg
for %%a in ("%drive%%dir1%%dir2%mixedwithtext\%file%") do echo %%~za

As for:
"I have tried sending the filename to another batch file. and using %~z1

But it will only work if I actually drop a file onto the batch file."

I assume that the file/path name contains a space so it is being broken up into multiple arguments if you surround it in double quotes you should get the same result as drag and drop, which adds the quotes automatically where necessary.


Report •
Related Solutions


Ask Question