FILES

mail@pastecode.io avatar
unknown
python
2 years ago
824 B
1
Indexable
Never
import os
from pathlib import Path

def match_file(name1 : str , name2 : str , extension :bool = False ):
    name1.replace("\n" , "")
    if not extension:
        return name1 == name2 
    else:
        return name1 == Path(name2.stem())

def make_new_file(file_path : str , new_directory : str):
    data = open(file_path).read()
    file_name = os.path.basename(file_path)
    open(new_directory + file_name , "w").write(data)
    print(file_name , "created" , end="\n")

search_file_names = open("").readlines()
search_dir = "/hdd/Downloads/"
searched_files = dict()

for folder , subfolder , files in os.walk(search_dir):
    for name in files:
        for file_name in search_file_names:
            if match_file(file_name , name , extension=True):
                searched_files[name] = os.path.join(folder, name)