Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

check file size from batch

Original Message
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.



Report Offensive Message For Removal


Response Number 1
Name: Mechanix2Go
Date: November 7, 2005 at 09:17:09 Pacific
Subject: check file size from batch
Reply: (edit)
Are you using w9x or w2000?


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

M2


Report Offensive Follow Up For Removal

Response Number 2
Name: mrdj
Date: November 7, 2005 at 09:53:23 Pacific
Subject: check file size from batch
Reply: (edit)
Win 2000....sorry, new to the site had my forum setting wrong.



Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: November 7, 2005 at 10:05:21 Pacific
Subject: check file size from batch
Reply: (edit)
:: 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


Report Offensive Follow Up For Removal

Response Number 4
Name: mrdj
Date: November 7, 2005 at 11:41:58 Pacific
Subject: check file size from batch
Reply: (edit)
Big thanks!!

Report Offensive Follow Up For Removal

Response Number 5
Name: vidukcom
Date: November 21, 2005 at 23:27:34 Pacific
Subject: check file size from batch
Reply: (edit)
I tried to use your solution but failed. It said 5000 was unexpected at this time.

Please help. Thanks.



Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: November 22, 2005 at 04:00:30 Pacific
Subject: check file size from batch
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 7
Name: vidukcom
Date: November 22, 2005 at 17:40:45 Pacific
Subject: check file size from batch
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 8
Name: Mechanix2Go
Date: November 22, 2005 at 22:41:37 Pacific
Subject: check file size from batch
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 9
Name: vidukcom
Date: November 22, 2005 at 23:34:29 Pacific
Subject: check file size from batch
Reply: (edit)
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..


Report Offensive Follow Up For Removal

Response Number 10
Name: Mechanix2Go
Date: November 23, 2005 at 00:22:10 Pacific
Subject: check file size from batch
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 11
Name: vidukcom
Date: November 23, 2005 at 01:05:49 Pacific
Subject: check file size from batch
Reply: (edit)
Dear M2,

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

Regards


Report Offensive Follow Up For Removal

Response Number 12
Name: Mechanix2Go
Date: November 23, 2005 at 01:22:41 Pacific
Subject: check file size from batch
Reply: (edit)
Hi vidukcom,

Glad you got it.

regards,


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

M2


Report Offensive Follow Up For Removal

Response Number 13
Name: vidukcom
Date: November 23, 2005 at 17:49:10 Pacific
Subject: check file size from batch
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 14
Name: Mechanix2Go
Date: November 23, 2005 at 20:16:22 Pacific
Subject: check file size from batch
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 15
Name: vidukcom
Date: November 24, 2005 at 00:45:44 Pacific
Subject: check file size from batch
Reply: (edit)
Dear M2,

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

Thanks a lot for your help.

Regards.


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: check file size from batch 

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




XP Installed to G?

exessive internet traffic

ZoneAlarm Question. Blocked Connect

Windows Live Messenger Problem

Delete $Uninstall after SP3 updates


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

All content ©1996-2007 Computing.Net, LLC