Skip to main content

Posts

Showing posts from August, 2019

Get the list of all the files and directories

Function Use: To print all the directories in a folder/sub-folder or directory import os def get_list_or_dir(local_dir):     for dir_or_file in os.listdir(local_dir):         if os.path.isdir(dir_or_file):             path = os.path.join(local_dir, dir_or_file)             print(dir_or_file, 'This is a directory')             get_list_or_dir(path)         else:             print(dir_or_file) Path = os.getcwd() or define the path from where you need a file Function Call: get_list_or_dir(path)

Get the list of all the files and directories

Function Use: To print all the directories in a folder/sub-folder or directory import os def get_list_or_dir(local_dir):     for dir_or_file in os.listdir(local_dir):         if os.path.isdir(dir_or_file):             path = os.path.join(local_dir, dir_or_file)             print(dir_or_file, 'This is a directory')             get_list_or_dir(path)         else:             print(dir_or_file) Path = os.getcwd() or define the path from where you need a file Function Call: get_list_or_dir(path)