gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
How to get list of files in directory in Python?
- User
How to get list of files in directory in Python?
- Assistant
To get a list of files in a directory using Python, you can use the
osmodule. Here's an example:pythonimport os # Specify the directory path directory = '/path/to/directory' # Get the list of files in the directory file_list = os.listdir(directory) # Print the list of files for file in file_list: print(file)