Files
python_skripte/play_with_os/os_play.py
2024-07-08 13:40:49 +02:00

43 lines
1.5 KiB
Python

#! /usr/bin/env python3
import os
def show_all_files_directory(dir_path = str, search_endung = False, search_string = False):
li_all = []
for (root_folder, dirs, files) in os.walk(dir_path, topdown=False):
for name in files:
FullPATH = [str(os.path.join(root_folder, name)), name]
if not search_endung is False:
if FullPATH.endswith(search_endung):
li_all.append(FullPATH)
elif not search_string is False:
if not FullPATH.find(search_string) == -1:
li_all.append(FullPATH)
else:
li_all.append(FullPATH)
return li_all
def main(check_list = list, main_folder_in = str):
output_list = []
for folder_name in check_list:
main_folder =main_folder_in + os.sep + folder_name
if os.path.exists(main_folder):
run_file_check = show_all_files_directory(dir_path=main_folder)
for file_name in run_file_check:
output_list.append(str(folder_name + '=' +file_name[1]))
else:
print(main_folder, "existiert nicht")
return output_list
# print(os.get_exec_path())
if __name__ == "__main__":
check_folders = ["Downloads", "Dokumente", "diokdkij"]
running_main = main(check_list=check_folders, main_folder_in=os.sep + "home" + os.sep + "jonnybravo")
for run in running_main:
with open("output_file", "a") as file:
print(run, file=file)