jam@sequoia.execu.com (James LeBas) (08/25/90)
"What I am using amounts to hardly more than stone knives and bearskins." Does anybody know how to get a .bat file to test for the length of another file; specifically, for the presence of a zero byte file? A .bat file I use tests for the presence of certain files and if not found, pipes an echo to an errorlist file; in so doing, the errorlist file should contain all the error messages and can be thrown to the screen at the end of the .bat execution. The problem is, this statement: if not exist goodfile.txt echo goodfile.txt missing >> errlist creates errlist as a zero byte file, even if goodfile.txt exists. The presence of errlist should indicate that there is a problem. So if I can test for errlist's length, and act on that (by deleting it, if zero) then everything's copasetic. Thanks.
davidr@hplsla.HP.COM (David M. Reed) (08/26/90)
I have never found a way to get MS-DOS BATch files to preform this trick, which I have often had need for. Thus I turn to the MKS Toolkit which has this capability in its 'test' command. Not only can I test if a file is zero length, I can also test if a filename in a directory listing is that of another directory, and several other tests.
bud@cimage.com (Bud Howard/1000000) (08/27/90)
I guess few people know dos well enough! It is _VERY_ simple. REM First check to see if the file is missing and write to errfile. if not exist goodfile.txt echo Goodfile.txt is missing! >>errfile REM Copy the original to a new name (be sure that all names are unique.) copy errfile errfile2 >NUL REM Because DOS will not copy a zero length file, if it is a zero REM length file the second one will be missing and we can delete REM the first one. if not exist errfile2 erase errfile REM This is just a cleanup line so not to have duplicate files. if exist errfile2 erase errfile2 REM Here is where the errfile would be displayed to the screen. if exist errfile type errfile |more This is very simple and quick. bud P.S. THINK DOS!
cgordon@vpnet.chi.il.us (Gordon Hlavenka) (08/29/90)
>Does anybody know how to get a .bat file to test for the length of another >file; specifically, for the presence of a zero byte file? Microsoft distributed (with source!) a program called WHAT.COM with some versions of MASM. The file was redistributed on some BBSs; I'm not sure of the legality. WHAT checks several interesting things, and leaves its results in a variable in the master environment. Thus, you could do this: WHAT S GOODFILE.TXT if "%WHAT%" == "0" echo File is zero-length. WHAT also allows prompted input of strings, and other nifty things. Sounds like what you're looking for. ----------------------------------------------------- Gordon S. Hlavenka cgordon@vpnet.chi.il.us
37KGLLQ@CMUVM.BITNET (Tony Papadimitriou) (08/29/90)
>I guess few people know dos well enough! > if exist errfile type errfile |more instead: if exist errfile more <errfile 0 0 | :___/
tim@int13.hf.intel.com (Timothy E. Forsyth) (08/31/90)
jam@sequoia.execu.com (James LeBas) writes: >Does anybody know how to get a .bat file to test for the length of another >file; specifically, for the presence of a zero byte file? With normal DOS batch commands, NO. [The following batch line produces empty errlst even if goodfile.txt exists.] > if not exist goodfile.txt echo goodfile.txt missing >> errlist ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ I believe the relationship between the IF and >> is as I have marked above. There are two ways to keep from creating the errlist file, in the first all commands are in the same batch file; in the second you create a secondary batch file. Example 1: TEST.BAT <Leading batch file commands> IF NOT EXIST goodfile.txt GOTO missing GOTO continue :missing ECHO goodfile.txt missing >> errlist :continue <Trailing batch file commands> Example 2: TEST.BAT <Leading batch file commands> IF NOT EXIST goodfile.txt CALL missing.bat goodfile.txt <Trailing batch file commands> MISSING.BAT ECHO %1 missing >> errlist If you are going to be checking for the existance of a lot of files, I suggest you creat a batch file CHKEXIST.BAT which is a modification on example 1. TEST.BAT CALL chkexist.bat file1.txt . . . CALL chkexist.bat file2.txt . . . CALL chkexist.bat file2.txt CHKEXIST.BAT IF NOT EXIST %1 GOTO missing GOTO end :missing ECHO %1 missing >> errlist :end Hope this is of some help. Tim Forsyth (Disclaimer: This is just sharing of my own experiences with DOS batch files, and has nothing to do with my employer, Intel Corp.) -- Tim Forsyth, tim@int13.hf.intel.com or forsytim@ccm.hf.intel.com Intel Corp., Oregon MicroComputer Division, Hillsboro, Oregon, USA