Name: mrdj Date: November 7, 2005 at 08:48:08 Pacific Subject: check file size from batch OS: win 2000 CPU/Ram: 4g
Comment:
Is there a way to check the size of a file from a batch file? or at the very least a dir command that will return only file name and file size? I would like to simply check for a file size greater than some number and archive/delete when it grows beyond that point. ANY help would be appreciated THANKS.
Are you using w2k? If so, did you run the bat with a filename to check?
Here's a version with syntax checking:
:: 2big2.bat CALL with filename.ext @echo off if %1'==' echo which file? && goto :eof if not exist %1 echo %1 was not found && goto :eof if %~z1 GTR 5000 del %1 :: DONE
If at first you don't succeed, you're about average.
No, I am using Windows XP now. Yes, yesterday I change the word filename.ext with my file name, but failed.
Actually what I want to do is not the same with this case, but similar. I want to check whether the file size is 0 or not. If 0, I want to give message to the user and then abort the batch file.
:: chk4zero.bat @echo off if %1'==' echo usage is: %0 FILENAME.EXT && goto :eof if not exist %1 echo %1 was not found && goto :eof if %~z1 EQU 0 goto :0 goto :eof :: Put in any code you want to run if the file is not zero length.
:: :0 echo %1 is size zero :: DONE
If at first you don't succeed, you're about average.
Sorry there is another problem with my batch file. Actually it has worked fine with your script before, but I have to run it like this : chk4zero buj.rar.
Whereas, buj.rar is produced inside the batch file, so there is a process inside.
User will only type the batch file without even know the name of the file produced inside.
So, when user type chk4zero, I want to check inside the batch process whether the file produced is zero or not, if zero, I want to delete it.
My problem now is how to set %1 with the file name inside the batch file.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE