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.
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
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
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.
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.
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 5  Replies