Computing.Net > Forums > Windows 95/98 > check file size 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.

check file size from batch

Reply to Message Icon

Name: mrdj
Date: November 7, 2005 at 08:48:08 Pacific
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.




Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 7, 2005 at 09:17:09 Pacific
Reply:

Are you using w9x or w2000?


If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: mrdj
Date: November 7, 2005 at 09:53:23 Pacific
Reply:

Win 2000....sorry, new to the site had my forum setting wrong.



0

Response Number 3
Name: Mechanix2Go
Date: November 7, 2005 at 10:05:21 Pacific
Reply:

:: 2big.bat CALL with filename.ext
if %~z1 GTR 5000 del %1
:: DONE


If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: mrdj
Date: November 7, 2005 at 11:41:58 Pacific
Reply:

Big thanks!!


0

Response Number 5
Name: vidukcom
Date: November 21, 2005 at 23:27:34 Pacific
Reply:

I tried to use your solution but failed. It said 5000 was unexpected at this time.

Please help. Thanks.



0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: November 22, 2005 at 04:00:30 Pacific
Reply:

vidukcom,

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.

M2


0

Response Number 7
Name: vidukcom
Date: November 22, 2005 at 17:40:45 Pacific
Reply:

Dear M2,

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.

Would you mind please help. Thanks a lot.


0

Response Number 8
Name: Mechanix2Go
Date: November 22, 2005 at 22:41:37 Pacific
Reply:

Hi,

Try this:

:: 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.

M2


0

Response Number 9
Name: vidukcom
Date: November 22, 2005 at 23:34:29 Pacific
Reply:

Hi,

So sorry again for me being so stupid. I still don't understand.

if %1'==' echo usage is: %0 FILENAME.EXT && goto :eof

About above line, I am confused, how to set the file I want to check as %1. For example, the file name is buj.rar.

Please help again. Thanks..


0

Response Number 10
Name: Mechanix2Go
Date: November 23, 2005 at 00:22:10 Pacific
Reply:

The %1 means the first command line "parameter".

So in this case you should run this command:

chk4zero buj.rar



If at first you don't succeed, you're about average.

M2


0

Response Number 11
Name: vidukcom
Date: November 23, 2005 at 01:05:49 Pacific
Reply:

Dear M2,

Thanks so much. I understand now.
It works properly.

Regards


0

Response Number 12
Name: Mechanix2Go
Date: November 23, 2005 at 01:22:41 Pacific
Reply:

Hi vidukcom,

Glad you got it.

regards,


If at first you don't succeed, you're about average.

M2


0

Response Number 13
Name: vidukcom
Date: November 23, 2005 at 17:49:10 Pacific
Reply:

Hi M2,

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.

Please help again. Thanks a lot.

Regards.


0

Response Number 14
Name: Mechanix2Go
Date: November 23, 2005 at 20:16:22 Pacific
Reply:

Hi,

This will check the size of buj.rar and if it is zero, delete it.

:: chkrar0.bat
@echo off
for %%R in (buj.rar) do if %%~zR equ 0 del buj.rar
:: DONE



If at first you don't succeed, you're about average.

M2


0

Response Number 15
Name: vidukcom
Date: November 24, 2005 at 00:45:44 Pacific
Reply:

Dear M2,

Big thanks. I now have succeeded creating the batch file I need.

Thanks a lot for your help.

Regards.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Windows 95/98 Forum Home


Sponsored links

Ads by Google


Results for: check file size from batch

Cannot Open Truncated File Names from Co www.computing.net/answers/windows-95/cannot-open-truncated-file-names-from-co/77269.html

Quick question concerning file size... www.computing.net/answers/windows-95/quick-question-concerning-file-size/52649.html

oullook express max file size www.computing.net/answers/windows-95/oullook-express-max-file-size/167418.html