File Search (Beginner Users)

I'm back!

I've put together another quick Python script that asks the user which kind of file type they wanna search, and it write back all the file in the system with that file extension.
Not sure how much can be helpful, but it might serve as idea for anyone that wants to practice or expand it even further!

Here's the code:

import fnmatch
import os

rootPath = '/'
pattern = str(input("Which type of file You wanna search today?"))

for root, dirs, files in os.walk(rootPath):
    for filename in fnmatch.filter(files, pattern):
        print( os.path.join(root, filename))

I created an executable for who doesn't know how to create one (I've used pyinstaller)
Here the link for the download: WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free (if this is not permitted i will remove it)


  1. Unzip the file
  2. Place the file_search file wherever you prefer
  3. Open your terminal
  4. Navigate into the folder where you put the script
  5. Run it by writing: ./file_search
  6. The script will ask You which kind of file type You wanna search
  7. Write the file type You wanna search using the following formatting: *.mp3 (change mp3 with whatever file You are looking for)
  8. Press Enter
  9. All the files with the specified extension are now listed in your terminal.

I hope this might be helpful for someone, feel free to change / expand / make yours as much as you can, and if there are any question, please let me know!


So it's doing exactly what this command is doing?
find / -iname "*.mp3" -print

It is the same, the main point of the script is that you can experiment and expand the functionality - and why not, learn a bit of python.
I found these little things very useful in my learning process, and I hope it might serve as an inspiration like it was for me when i started.

1 Like

would be interesting to compare the performance of the find command and your script. Measuring time, CPU, Memory and IO utilization. You know, just to learn what an impact it has to write your own code vs native system code.

If the cost of learning coding is just a bit more memory usage, I consider that a bargain.

It is a beautiful thing to be be able to get in and learn and play around with the code to make changes or develop better understanding. And perhaps the code could be refined, later or even the native code may work better sometimes, too. But learning is always the Best Way To Go.
It is also very beneficial for Open Source as the more knowledge a person acquires, the more they can examine and find issues with existing open source code, improving on it for the community as a whole.

1 Like