I am making a file/ folder searcher in python() like the window explorer search bar), but i realised that 'os real path ' only finds one folder with that name, how do i search for all folders with a given name, and not what is in them, but where i can find these folders and files?
import webbrowser
from tkinter import *
import os
tk = Tk()
opens a tk
web1 = 'www.'
web2 = '.com'
en = Entry(tk)
en.grid()
'''types = input('What platform do you want to search? ')'''
old input method
bind = 0
def work():
global tk1, term, en1, tabUrl, end
tk1 = Tk()
en1 = Entry(tk1)
en1.grid(row=1)
b = Button(tk1, text='Go', command=fi1)
b.grid(row=2)
if types.upper() == 'GOOGLE':
tabUrl = "https://google.com/search?q=";
end = ("&cad=h")
l = Label(tk1, text='What would you like to search?')
l.grid(row=0)
'''term = input("What would you like to search? ")'''
if types.upper() == "YOUTUBE":
tabUrl = "https://www.youtube.com/results?search_query=";
'''term = input("What would you like to search? ")'''
l = Label(tk1, text='What would you like to search?')
l.grid(row=0)
if types.upper() == 'INTERNET' or types.upper() == 'WEB' or types.upper() == 'THE WEB' or types.upper() == 'WEBSITE':
l = Label(tk1, text='What website would you like to open?')
l.grid(row=0)
if types.upper() == 'COMPUTER':
l = Label(tk1, text='What folder would you like to open?')
l.grid(row=0)
tk1.mainloop()
'''def find_all(name, path):
for root, dirs, files in os.walk(path):
for name in files:
print(os.path.join(root, name))
for name in dirs:
print(os.path.join(root, name))'''
def find_all(name, path):
result = []
for root, dirs, files in os.walk(path):
if name in files:
result.append(os.path.join(root, name))
print( result)
def fi(self):
global term
term = en1.get()
if types.upper() == 'GOOGLE':
term = term.replace(' ', '%20')
webbrowser.open(tabUrl + term + end)
if types.upper() == "YOUTUBE":
term = term.replace(' ', '+')
webbrowser.open(tabUrl + term)
if types.upper() == 'INTERNET' or types.upper() == 'WEB' or types.upper() == 'THE WEB' or types.upper() == 'WEBSITE':
if term.upper() == 'GOOGLE':
webbrowser.open('www.google.com')
else:
webfind1 = term.find(web1)
webfind2 = term.find(web2)
if webfind1 >= 0 and webfind2 >= 0:
webbrowser.open(term)
else:
tk1.destroy()
tk2 = Tk()
la = Label(tk2, text='Your website must have a ".com" and a "www."')
la.grid()
tk2.mainloop()
if types.upper() == 'COMPUTER':
term = term
if os.path.exists(term) == True:
find_all(term, r'C:\Users\MUM')
#place = os.path.realpath(term)
#print(os.path.realpath(term))
#os.startfile(place)
def fi1():
global term
term = en1.get()
if types.upper() == 'GOOGLE':
term = term.replace(' ', '%20')
webbrowser.open(tabUrl + term + end)
if types.upper() == "YOUTUBE":
term = term.replace(' ', '+')
webbrowser.open(tabUrl + term)
if types.upper() == 'INTERNET' or types.upper() == 'WEB' or types.upper() == 'THE WEB' or types.upper() == 'WEBSITE':
if term.upper() == 'GOOGLE':
webbrowser.open('www.google.com')
else:
webfind1 = term.find(web1)
webfind2 = term.find(web2)
if webfind1 >= 0 and webfind2 >= 0:
webbrowser.open(term)
else:
tk1.destroy()
tk2 = Tk()
la = Label(tk2, text='Your website must have a ".com" and a "www."')
la.grid()
tk2.mainloop()
if types.upper() == 'COMPUTER':
term = term
if os.path.exists(term) == True:
find_all(term, r'C:\Users\MUM')
#place = os.path.realpath(term)
#print(os.path.realpath(term))
#os.startfile(place)
def finding(self):
global types, bind
types = en.get()
tk.destroy()
work()
tk1.bind('<Return>', fi)
def finding1():
global types, bind
types = en.get()
tk.destroy()
work()
tk1.bind('<Return>', fi)
if bind == 0:
tk.bind('<Return>', finding)
tk.mainloop()