Fuzzy File Searching Tool in Python

NeuralNine · Intermediate ·💻 AI-Assisted Coding ·3y ago

Key Takeaways

The video demonstrates how to build a fuzzy file searching tool in Python, utilizing various libraries and techniques to create an efficient search function.

Full Transcript

what is going on guys welcome back in today's video we're going to build a simple file searching tool in python which also allows for fuzzy search so let's get right into it [Music] all right so we're going to build a simple file searching tool in python today and the basic search will be done with core python libraries so without installing any external modules however for the fuzzy search that we also want to enable we need to install an external library that we have used on this channel before in another video called fuzzy wuzzy basically allowing for fuzzy text matching or fuzzy string matching uh so we can take a string and see if it is contained in another string but not exactly but based on similarities so we can look at similarity measures to see okay is this string somewhat uh what we're looking for and because of that we can enable fuzzy search so if we want to use that we need to install it so we open up a command line cmd on windows to terminal on linux and mac and we use pip so either pip or pip 3 to install fuzzy wuzzy like this so in my case already satisfied so already installed in addition to that we also need to install pip 3 install on linux just pip install on windows python dash leaven stein or levenstein i'm not sure how it's pronounced and this is also satisfied in my case here so once we have these libraries installed we can start by opening up a new python file in my case i'm going to call it main.py and here we're going to start by importing first of all the os module and second of all from fuzzy wuzzy we're going to import fuss and then we're going to ask the user for uh some input so we're going to ask okay what directory do you want to look for files in and what file types do you want to look for and stuff like that we're going to start with the root directory we're going to say root gear equals input enter the root directory for your search so this will just ask for a simple root directory this can be a dot to uh specify the current directory this can be dot dot slash to specify the parent directory or it can be an absolute path like slash home user or on linux or maybe c users and your username on windows whatever you provide here this script by the way works on windows and on linux so it's platform independent in addition to that we're going to ask for file types so we're going to say here file underscore types is going to be equal to input enter the file endings to look for like this and we can say here um empty equals all so basically if we say uh if we don't enter anything if we just press enter this is going to look for all files and then we also want to say the fuzzy search query is going to be input enter a fuzzy search query like this here and we can also say here empty equals none so if we don't enter one we're gonna find all the files here as well so this is the input that we get from the user now based on that we're going to find all the files uh in the root directory that have the certain file types and that match somewhat the fuzzy search so we're going to say first of all the file types are going to be individual file types separated by spaces maybe we should also add this here separate by spaces there you go we're going to say here file types equals file types dot split on white spaces here so this results then in a list of file endings like txt py uh docx whatever and we're going to then see if the files that we find end with the with those file endings with one of those file endings so we're going to say now here for root and directories and files in os dot walk this is the function we're going to use to browse the root directory with all the sub directories here we're going to save for um those things in os walk root there we're going to say now for each name that we find in the files here so for each file name that we see here we're going to say if this name ends with and now we're going to say uh we're going to pass a tuple here because we can pass a tuple with multiple strings to say if it ends with one of them so we don't have to say uh if the file ending is in the file types or for each file type check if it ends with we can just say if name dot ends with tuple file type so ft for ft in file types or if the file types 0 is equal to nothing because that is the case um if we that is the case essentially if we don't provide any file type so then we can just find all the files if that is the case what we're going to do is we're going to check also for the fuzzy search so we're going to say if fuzzy or actually if fuss dot token underscore sword underscored ratio if that between fuzzy search dot lower and the actual file name dot lower if that thing is above 50 or if it's empty so if we didn't provide anything so fuzzy search is equal to just an empty string here if that is the case one of those two things is the case then we're going to print the root directory plus the separator of the respective operating system so os dot sep plus name and this will then find the file so we can go out here we can write and quit and now we can create here a simple file i'm gonna say test.txt and i can say python3main.py and i can say okay i want to look in this directory for a txt file for example and i don't want to have a fuzzy search query there you go it found it now if i do the same thing this directory here dot txt ending uh and i want to find hello world as a search query we will not find the text the test.txt file whereas if i say here um enter the file index look for again.txt i'm not sure if i type tst if it's going to find test there you go it finds test so this is also how this works here now let's go ahead and go up a directory which is my python directory in general where i have all the recorded and prepared projects and if i now look for a py file ending and i don't enter a query you can see all these things here all the videos that i have recorded already probably all tutorials that are already online you can see all the main py files here that i have prepared for the videos and um i can also do the same thing here again go up a directory look for py and look for txt files and uh don't enter a fuzzy search query so you can also find here some txt files of different sorts and you can see it goes up a directory it goes into recorded it goes into udp chat for example and then it finds the py file so it goes deeper into the file uh structure it goes into the subdirectories as well and now let's go ahead and just look in the parent directory for no file type but for example for udp um okay oh actually this does not work because um udp is the directory the files are named differently so let's look for something else let's uh look for all the file types but for server for example or just serv and then you will find service secret and server.py so we have a bunch of different uh files here that are similar to the word surf this is the fuzzy search element of that so that's it for today's video i hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this channel and hit the notification bell to not miss a single future video for free other than that thank you much for watching see you next video and bye [Music] you

Original Description

Today we build a fuzzy file searching tool in Python. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm 🎵 Outro Music From: https://www.bensound.com/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches how to build a fuzzy file searching tool in Python, covering topics such as efficient search functions and coding techniques. By the end of the video, viewers will be able to create their own file searching tools. The tool is useful for quickly finding files on a computer.

Key Takeaways
  1. Install necessary Python libraries
  2. Create a new Python script
  3. Define a function for fuzzy file searching
  4. Implement the search function
  5. Test the tool
💡 The key to creating an efficient fuzzy file searching tool is to utilize the right libraries and techniques, such as using a combination of string matching algorithms and file system navigation.

Related AI Lessons

Up next
Azure Security Priorities for 2026: Identity, Governance, AI Security & Zero Trust
Valto Microsoft Specialists
Watch →