Solved

DOS batch errorlevel

Posted on 2001-06-21
12
1,318 Views
Last Modified: 2013-12-28
The following code, in a DOS batch file, works on NT. However, it does not work on Windows 98. It always prints "file is empty." How to make this work or how do I judge if a file is empty on Windows 98?

find /v "" file
if errorlevel=1 echo file is empty.

Thanks.
0
Comment
Question by:txholdem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 7

Expert Comment

by:Ajnin
ID: 6214287
What do you mean by empty file? A text file without any text?
Please explain
0
 
LVL 1

Author Comment

by:txholdem
ID: 6214328
yes. a file that has nothing in it. its size is zero byte.
0
 
LVL 7

Expert Comment

by:Ajnin
ID: 6214468
You can check by the size, but normally Windows98 doesn't keep files that are zero bytes in size.

Every now and then you may see it display a file that is zero bytes but you won't be able to delete it because windows can't actually see it. If you reboot the file will be gone.

I guess to answer your question Windows 98 doesn't keep empty files. I'll see if I can find a way to check via a batch file.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 11

Expert Comment

by:griessh
ID: 6216618
Ajnin, sorry, but I have to disagree.

Windows98 certainly keeps 0 byte files! And they won't get deleted! I guess you were looking into the ../temp directory when you noticed that.
I am using empty files as locks and they stay alive and can be deleted as every other file.

======
Werner
0
 
LVL 11

Expert Comment

by:griessh
ID: 6216682
Ajnin, sorry, but I have to disagree.

Windows98 certainly keeps 0 byte files! And they won't get deleted! I guess you were looking into the ../temp directory when you noticed that.
I am using empty files as locks and they stay alive and can be deleted as every other file.

======
Werner
0
 
LVL 11

Accepted Solution

by:
griessh earned 30 total points
ID: 6216730
txholdem

You could use the copy command, that doesn't copy zero length files. Here is an example (very rough, but it works). I am sure from here on you can deal with it yourself, if not I'll give it another shot. Just let me know.

rem Try this with an empty file source1
rem ===================================
:step1
copy source1 temp > nul
if not exist temp goto empty1
echo source1 is not empty
del temp
goto step2

:empty1
echo file source1 is empty
goto step2


rem Try this with an non-empty file source2
rem =======================================
:step2
copy source2 temp > nul
if not exist temp goto empty2
echo source2 is not empty
del temp
goto end

:empty2
echo file source2 is empty
goto end

:end


It's a painful process, but it works down to MSDOS 5 at least.

Good Luck

=====
Werner
0
 
LVL 7

Expert Comment

by:Ajnin
ID: 6218083
I still disagree. There is no way to put zero bytes of data on your HD. What would be put on the HD? The file has to have atleast one bit (If it was only one bit then windows will report it as 0KB since it rounds off.)

txholdem, I know your question is actually on the batch file itself. I'm still looking for a command that will let you know the size of the file. griessh's comment might be what you need though.

Let us know
Regards
0
 
LVL 11

Expert Comment

by:griessh
ID: 6218124
Ajnin

Just try it, it is so easy. Create a file with no content. That doesn't mean it won't take up space, it just means there are 0 bytes in it. Do a "edit a", "File Save", "File Exit" on command prompt. You will see a file 'a' with 0 length and you can delete it and it will be there until you delete it.
The copy tricks is proven to work, I do that myself in smaller cleanup batch files.

======
Werner
0
 
LVL 1

Author Comment

by:txholdem
ID: 6218936
griessh,

That was tricky. I tried copying a 0-byte file and nothing was copied. So i guess your method should work. Even though I've done it by perl script and it's much easier! That takes care of all the differences between NT and 9x.

What I still don't understand though is if 'errorlevel' is a DOS key word, how come NT recognizes it while 9x does not?

0
 
LVL 1

Author Comment

by:txholdem
ID: 6218958
Ajnin, thanks for your help.

>There is no way to put zero bytes of data on your HD. What would be put on the HD?

why do think so? Doesn't the OS write the name of the file some where on the HD and a reference to its contents somewhere else? In this case, the referenced address contains nothing?
0
 
LVL 7

Expert Comment

by:Ajnin
ID: 6219022
Well griessh you appear to be right about the zero byte file.

In my experience the only time I ever saw a 0 byte file was during a faulty download. I never actually thought that a ASCII file with no text was 0 bytes. I always thought that it had a bit or two on it.

Yes txholdem, you hit the nail on the head with the reason why it would be possible. It is the FAT (File Allocation Table) that stores info of the file and its location. "In this case, the referenced address contains nothing?" is exactly correct.
I just couldn't get the concept through my head until griessh suggested to try it and then I had to figure out why it was possible.
Always learning.

Glad your problem was fixed txholdem.
And thanks griessh.
Regards


0
 
LVL 11

Expert Comment

by:griessh
ID: 6219178
>>'errorlevel' is a DOS key word, how come NT recognizes it while 9x does not?

I think it is not the errorlevel that fails, it is the find that behaves different. And admit 'find ""' is an unusual request. Doesn't every file contain an empty string? Apperently not the find in Win98.
I just wonder, doesn't relying on a failed 'copy' also just use a misbehaviour? A couple of UNIX features are certainly missing in Win.

Ajnin, you made me insecure. I had to sit down on a couple of different WinXX systems and try it myself :-)

======
Werner
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question