1.

Solve : check file size?

Answer» OK i need to do a batch file that would check for the size of a text file all i want is to know the size ifts 0 or not, any one can help.
thanksYou have to jump thru hoops to do this one:

Sample Only

@echo off
dir filename.ext > dummy.txt
findstr /i "xpBackup.vbs" dummy.txt > dummy.dat
for /f "tokens=1-4*" %%a in (dummy.dat) do (if %%d EQU 0 ...
del dummy.dat
del dummy.txt

The above is just to give you some ideas on how to go about it. You'll have to jigger the code to run on your machine. YMMV.

Hope this helps. im not too good at batch so this is not making too much sense,
the file i wanna check is c:\error1.txt
do i really need thse dummy files and why a for loop.
helpOK. This little piece of doggerel will eliminate one of the dummy files. The reason for the loop is that the FOR statement offers the only batch command that will read INPUT from a file. The fact that garbage.dat contains just one record is to your advantage so a value for %%d can be evaluated. Note: The FIND command will produce to two lines of output.

Batch file programming is not only knowing all the commands and their obscure switches, but knowing how to combine them so that nothing makes sense....the result just works.

A batch file is not the best solution for your request. It's UNREALISTIC to use cryptic code to accomplish simple tasks. If you ever have to revisit this file (and you will), you'll wonder "what the *censored* was I thinking". I would substitute WINDOWS Script for it's simplicity and readability.

Code: [Select]
@echo off
dir c:\error1.txt | findstr /i "error1.txt" > garbage.dat
for /f "tokens=1-4*" %%a in (garbage.dat) do (echo size error1.txt ^= %%d)
del garbage.dat


Feel free to change the ECHO statement to an IF statement and perform what ever action you need to do.

Hope this helps. thanks for your help, and the fact im using batch is thats what the boss wants he wants everything consistent and this is a good for me as i never worked with batch before.


Discussion

No Comment Found