Search files with Python

With Python you can go look for files in such a fast way and you can also do things like memorize the path… etc.

Let’s go take a look at the code and follow my explanation in the video below.

import os

def searchfiles(word_in_title='example', folder='H:\\'):
    """Create a txt file with all the file of a type"""
    with open(word_in_title + "_files.txt", "w", encoding="utf-8") as filewrite:
        for r, d, f in os.walk("H:\\"):
            for filetitle in f:
                if word_in_title in filetitle:
                    filewrite.write(f"{r + filetitle}\n")

# looking for png file (fonts) in the hard disk H:\
searchfiles('.png', 'H:\\')

 

 


Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.