Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking the file size and quit if empty

Status
Not open for further replies.

teky

Programmer
Mar 24, 2000
55
US
Hello everybody,

I want to write a script in DOS which checks for the file size or checks if the file is empty.
If the file is empty then it should quit.

Thanks,
Teky.


 
Do you mean a batch file? or is there a specific language you wish to use? --MiggyD

It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
If you are using Qbasic, or going to compile under qb4.5, try this


Open "somefile" for input as #1
If LOf(1) <>0 then goto continue
end

continue:

or sommin similar
 
While Rathgar's code will work, here's a little upgrade. The GOTO statment sometimes causes problems, especialliy when compiling, so use this instead:

OPEN file$ FOR RANDOM AS #1
IF LOF(1) = 0 THEN END
'rest of your code here
 
Here's one that should work:

CALL check4file(filename$,a%)
IF a%=0 THEN END

SUB check4file (filename$,a%)
f%=FREEFILE
OPEN filename$ FOR APPEND AS #f%
IF LOF(f%)= 0 THEN a% = 0 ELSE a% = 1
CLOSE #f%
IF a% = 0 THEN KILL filename$
END SUB
 
Does everybody know something I don't?

Is this question in regards to DOS or BASIC or COBOL or FORTRAN or PASCAL or C++ or VB 1.0 or (whatever)? If so please clarify.

TO TEKY:

Please rephrase your question [red]AND[/red] add more details like what programming language you'll be using for this SCRIPT. --MiggyD

Never be afraid to try something new. Remember that amateurs built the Ark. Professionals built the Titanic.
 
MiggyD,
As the question was raised in this (BASIC:Microsoft) forum so it's not unreasonable to think that the questioner was dealing with one of the Microsoft Basic dialects.

Since QBasic predominates - for DOS platforms - it is most likely that the question referred to QBasic.

For my part, I was merely adding to Rathgar's comments by giving another QBasic solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top