Use python to implement a file search function, similar to the Everything function

Ordinary people always record some fragment information into files and put them on the hard disk of the computer. After a while, you may not know where to put it, because there are too many folders on the computer. Searching software is generally used to find files, such as Everything software is very powerful, you can search files globally by inputting a name;

But the Everyting software can only match within the file, if you want to search for the content of the file, there is no way. Do you know if there is such a software on the market?

However, you can use python to do a simple search function to achieve this requirement;

Realization principle

  • Use os to traverse all files under the folder
  • Use the built-in open function to read the file contents and search for a match
  • In order to provide speed, add a multi-threaded execution method

Preparation

Only the multi-thread library threading needs to be used in the library, which is a third-party library and needs to be installed; the installation method is relatively simple, open the command line window; execute the command:

pip install threading

Wait for the installation to succeed;

Multithreading basics
A process is an executing instance of an application. Every running program is a process.
A thread is an integral part of a process, and a process can have multiple threads. In multi-threading, there will be a main thread to complete all operations of the entire process from beginning to end, while other threads will be created or exit during the running of the main thread.

Concurrency and Parallelism

Concurrency and parallelism are two concepts. Parallelism means that multiple instructions are executed on multiple processors at the same time; concurrency means that only one instruction can be executed at the same time, but multiple process instructions are quickly executed in rotation, making Macroscopically, it has the effect of multiple processes executing at the same time.

</

Guess you like

Origin blog.csdn.net/weixin_42551921/article/details/125837073#comments_25682692