Hello. How to do brute force files in python? - And if it finds a string that says Hello world! - then some logic will be executed.

I am an absolute beginner, but for me it is very important to solve this problem. I do not know where to start.

I don’t ask all the code, although it would be a piece that will guide the solution.

  • The algorithm is divided into two parts: getting a file and searching for a string in it. The first is the os.walk method, which will return a list of folders and files. With the second method open, which will open the file and read its contents. - gil9red
  • 1- What does "file search" mean? Do you want a list of files to get? What is the criterion? By extension? For example, pathlib.Path.cwd().rglob("*.txt") finds all txt files in the current directory tree (recursively). 2- what does "find the string" mean? Whole line? Or is it enough to match a substring? What if a substring occurs several times in a single "\ n" string? In one file? What do you want to pass as an argument for the action? 3- the question of getting a list of files and the question of searching within a single file is better (more useful for other visitors to the site) separately set (for the context you can give a link - jfs

0