battle to trap failure in for

H

Henry

I have a script with which I'm battling with. I'm checking
file sizes for specific files on certain servers.
This script works 100% except when a failure ocurs with
the directory. I would like to write out an error
message when this ocurs. I've tried all sorts of things
but the error gets lots with the find command.
Any suggestions...?

for /f "tokens=1-5 delims=:" %%a in (server_list.txt) do (
for /f "tokens=1-5 delims= " %%i in ('"dir "\\%%a\%%b$%%c%%
d" | findstr /e bytes"') do (
echo %%a %%b:%%c%%d = %%k %%l >> %%a_Sizes.txt
)
)
 
M

Matthias Tacke

Henry said:
I have a script with which I'm battling with. I'm checking
file sizes for specific files on certain servers.
This script works 100% except when a failure ocurs with
the directory. I would like to write out an error
message when this ocurs. I've tried all sorts of things
but the error gets lots with the find command.
Any suggestions...?

for /f "tokens=1-5 delims=:" %%a in (server_list.txt) do (
for /f "tokens=1-5 delims= " %%i in ('"dir "\\%%a\%%b$%%c%%d" | findstr /e bytes"') do (
echo %%a %%b:%%c%%d = %%k %%l >> %%a_Sizes.txt
)
)

Then check for the existence of that dir before the second for
Without knowing the values you read with the first for its difficult to
give any suggestion.
%%b seem to be single drive letter building system share names with $,
%%c has to include a backslash at start, %%d beeing another folder or
file?
Try something like:
if exist \\%%a\%%b$%%c%%d\NUL (
place the above for here
) else (
echo \\%%a\%%b$%%c%%d doesn't exist >> %%a_Sizes.txt
)
 
H

Henry

You are right on all you assumptions!
I initially wanted to keep all this in one command but
this works for me, THANKS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top