480 pts.
 DOS Script Help
I have the below DOS batch that checks the length of every file in the temp folder and display the file name(s) of any file with zero bytes. In addition, if there are no files in the directory the message “No Files in folder” will be displayed.

Software/Hardware used:
Windows XP
ASKED: October 1, 2010  6:39 PM
UPDATED: October 4, 2010  12:54 PM

Answer Wiki:
Try something like this: <pre>:CHKFILELEN set emptyFiles=0 for %%f in (*.*) do ( if %%~zf lss 1 ( set emptyFiles=1 echo %%f ) ) if %emptyFiles% == 0 (echo "No empty files found") goto END</pre>
Last Wiki Answer Submitted:  October 1, 2010  8:02 pm  by  carlosdl   63,580 pts.
All Answer Wiki Contributors:  carlosdl   63,580 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

The actual script didn’t get posted.

 63,580 pts.

 

It appears only a portion of my question is being displayed. Here is the rest of my question along with the batch file I need to improve:

I need this batch file to do an additional task; If files are in the folder and all are greater
than zero bytes I would like to echo a message, “No Empty Files found”.
Everything I have tried have not worked. Any help will be greatly appreciated.

@ECHO OFF
CD C:temp
if exist *.* goto CHKFILELEN
if not exist *.* goto MESSAGE

:CHKFILELEN
for %%f in (*.*) do (if %%~zf lss 1 echo %%f)
goto END

:MESSAGE
echo “No Files in folder”
goto END

:END

 480 pts.

 

Thank you Carlosdl for you quick response.

I ran a test with your changes and the correct message is displayed when the files are greater than 0 bytes. However, when I test it with files with 0 bytes I get an error message that states “echo was unexpected at this time.”

I tried fixing the below statement but still no luck.

for %%f in (*.*) do ( if %%~zf lss 1 ( set emptyFiles=1 echo %%f

 480 pts.

 

Hmmm. I tested it before posting.

Something as simple as writing two commands on the same line could be causing the problem.

Try copy-pasting it. If that doesn’t work, post your new version here.

 63,580 pts.

 

Carlosdl, your are so right. I did a copy and paste as you suggested and it worked perfectly.

I had no idea that putting the 2 commands on the same line would make such a difference in how the logic works.
Thank you so much for all your help and for taking the time to figure this out for me.
Have a great week.

 480 pts.