DOS Script Help

480 pts.
Tags:
Batch files
DOS
DOS Batch
Microsoft Windows XP
Scripting
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

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>

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    The actual script didn't get posted.
    70,200 pointsBadges:
    report
  • jutpro
    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 pointsBadges:
    report
  • jutpro
    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 pointsBadges:
    report
  • carlosdl
    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.
    70,200 pointsBadges:
    report
  • jutpro
    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 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following