Reputation: 1
For example, if I was to have it search and find a file named ex.exe, it should then prompt whether you'd like to open the file. Thank you.
Upvotes: 0
Views: 101
Reputation: 248
This code worked for me you can check it out if it works for you too.
import os
def find_files(filename, search_path):
result = []
# Wlaking top-down from the root
for root, dir, files in os.walk(search_path):
if filename in files:
result.append(os.path.join(root, filename))
return result
find_files("sample.pdf", "E:\\")
If you want to look for folders you can try this worked perfectly for me.
import os
start = "E:\\"
for dirpath, dirnames, filenames in os.walk(start):
if "dev" in dirnames :
print(dirnames)
To execute an exe file you can use the below methods:
import os
path = "C:/"
os.chdir(path)
os.system("example.exe")
Upvotes: 1
Reputation: 41
You can import os then with the help of os.system("pass any windows cmd here") like regular file search make it happen
Upvotes: 0