Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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 sizeas plain DOS doesn't copy empty files.
However that isn't true with emulated DOS in NT kernel systems (Windows NT/2K/XP).

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

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 0should 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.

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

Hi M2, smart and interesting trick, only one note:
Copy MyFile Nul > Nul
If ErrorLevel 1 Echo Copy failed as MyFile's size is 0or
Copy Myfile Test > Nul
If not exist Test Echo MyFile is 0 sizerequire internal command only while FC solution relies on an external executable (FC).
Just a 20/20 insight, but worth to be pointed out.

Hi IVO,
Yeah, I always try to use internals only.
If at first you don't succeed, you're about average.M2

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

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

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

How about:
Mystery visitor, sign in please.
If at first you don't succeed, you're about average.M2

"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 !!!!!

![]() |
![]() |
![]() |

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