How to loop through files in a directory using batch script -


I batch am relatively new to scripting, I have to hide through a directory that requires a script in which the 3 log files and Czech errors and warnings, I am not very clear on looping bit I wrote a little code Please help me correct it ... %% IN (% C: \ Program Files (x86) \ \ * log for <% p>
  * ") Finder / C:" 0 Alerts "%% Set one result 1 =% error level / Khojastrik / C: "0 Non-Filtelr" %% a result set = 2% error level% findstr / c: "0 FatalErrors" %% result set = 3% Error Level% done if% result1% & amp; % Result 2% & amp; % Result3% EQU 0 (Exit 0) Other (Exit 1)  

This That's what I think you should do

  for %% an IN ("C: \ Program Files (x86) \" & lt; installloc & gt; * * * * Log * ") are trying (to %% b) to (Alerts Nonfatattl errors FaltalErrors) (Findstr / L / C: "0 %% B" "%% ~ FA" If error Level 1 exit / B1)) exit / B <  

This will search for all the files in the folder for any signal string. If none of them have been found, exit with Error 1. If all the strings are found in the files, the error level exit with 1

If you have then 10 warnings This code will fail (an example) Because the discovered text was found. The search string should be better defined based on the actual file content. Or, if the search text is placed at the beginning of the line, you can add / b to the findstr command, to indicate that at the beginning of the match What should be the line

There are some problems with your original code:

In batch files, for the closing bracket for the command ( .. (set) ) should be in the same line as the the keyword, and the command in the order should be attached to the block of rows (if one there is more than one) in parentheses Therefore, the Parser can know which lines have to be repeated and the open brackets of this block should be in the same line as Not keyword.

In addition, AND operator is not in the batch if command if you want to keep your original syntax, then

 Should be written as  if condition condition condition  

and after that, the commands will only be executed when three conditions are correctly evaluated.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -