Computing.Net > Forums > Disk Operating System > to check whether file size is 0 not

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.

to check whether file size is 0 not

Reply to Message Icon

Name: chaits_vijay
Date: February 9, 2006 at 05:37:40 Pacific
OS: MSDOS
CPU/Ram: Intel Pentium 4 256 MB RA
Comment:

I want to check whether a file contains data or it is blank in MSDOS.How can I do that?
I want to create a batch file, in which depending upon the check results, I would like to perform certain actions.

Required DOS Drivers for Compaq HP Laptop NX9010



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: February 9, 2006 at 05:47:21 Pacific
Reply:

If you are running true plain DOS, i.e. MS-DOS 6.22 or previous, you just have to copy the file and check for the target one, e.g.

Copy Myfile Test
If not exist Test Echo MyFile is 0 size

as plain DOS doesn't copy empty files.
However that isn't true with emulated DOS in NT kernel systems (Windows NT/2K/XP).


0

Response Number 2
Name: Mechanix2Go
Date: February 9, 2006 at 13:24:48 Pacific
Reply:

Hi IVO,

Neat. I didn't know that.

Does DOS set an errorlevel if the copy fails?

Does this also fail?:

copy myfile nul


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

M2


0

Response Number 3
Name: IVO
Date: February 10, 2006 at 05:39:54 Pacific
Reply:

Hi M2,

from a theoric point of view the statements

Copy MyFile Nul > Nul
If ErrorLevel 1 Echo Copy failed as MyFile's size is 0

should work, but, as ErrorLevel codes are quite questionable in plain DOS, beter to experiment.

At this time I do not have a DOS on hand (I use Bochs X86 emulator to run plain DOS and FreeDOS, but now it is out of work), so I can't answer you definitely.

By the way the same behavior applies to the DOS 7.X under Windows 9X/ME.


0

Response Number 4
Name: Mechanix2Go
Date: February 11, 2006 at 03:32:00 Pacific
Reply:

Hi IVO,

I'll boot in DOS and check it out.

Another way:

type nul>0
fc myfile 0
if errorlevel 1 echo "myfile" is not zero


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

M2


0

Response Number 5
Name: IVO
Date: February 11, 2006 at 06:11:57 Pacific
Reply:

Hi M2, smart and interesting trick, only one note:

Copy MyFile Nul > Nul
If ErrorLevel 1 Echo Copy failed as MyFile's size is 0

or

Copy Myfile Test > Nul
If not exist Test Echo MyFile is 0 size

require internal command only while FC solution relies on an external executable (FC).

Just a 20/20 insight, but worth to be pointed out.


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: February 11, 2006 at 06:17:46 Pacific
Reply:

Hi IVO,

Yeah, I always try to use internals only.


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

M2


0

Response Number 7
Name: CWoodward
Date: February 11, 2006 at 18:56:54 Pacific
Reply:

Try this:

FOR /F %%A IN ("File") DO IF %%~zA EQU 0 ECHO "File" is 0 in size

"If it jams, force it. If it breaks, it needed replacing anyway."
-Murphy's Laws


0

Response Number 8
Name: Mechanix2Go
Date: February 12, 2006 at 01:59:10 Pacific
Reply:

There is no for /f in DOS.

Nor EQU


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

M2


0

Response Number 9
Name: CWoodward
Date: February 12, 2006 at 13:55:03 Pacific
Reply:

Sorry, I was thinking of the DOS in Windows XP

"If it jams, force it. If it breaks, it needed replacing anyway."
-Murphy's Laws


0

Response Number 10
Name: jboy
Date: February 13, 2006 at 20:32:48 Pacific
Reply:

Maybe it's time to change the forum name (again)

How about:

"Nothing at all to do with XP here - move along now"

Science is built up with facts, as a house is with stones. But a collection of facts is not more a science than a heap of stones is a home


0

Response Number 11
Name: Mechanix2Go
Date: February 13, 2006 at 20:39:53 Pacific
Reply:

How about:

Mystery visitor, sign in please.


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

M2


0

Response Number 12
Name: franki
Date: February 14, 2006 at 01:27:02 Pacific
Reply:

"Sorry, I was thinking of the DOS in Windows XP"

WTF ???? I thought looking at previous postings that there is no TRUE REAL MS-DOS in XP !!!!!


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 Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: to check whether file size is 0 not

File Size > 2MB www.computing.net/answers/dos/file-size-2mb/10893.html

File Size in DOS Batch file www.computing.net/answers/dos/file-size-in-dos-batch-file/3105.html

dos batch to check file date www.computing.net/answers/dos/dos-batch-to-check-file-date/12627.html