Fuzzy File Searching Tool in Python
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: AI Pair Programming
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Most useless toy I’ve ever built. Love it.
Medium · AI
Nano Banana 2 Lite
Simon Willison's Blog
Reading Anthropic's "When AI Builds Itself" Changed How I Think About AI and Software Engineering
Dev.to · Hemapriya Kanagala
When AI Writes Most of My Code: What Happens to My Identity as a Software Engineer?
Medium · AI
🎓
Tutor Explanation
DeepCamp AI