You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
623 B
22 lines
623 B
import os
|
|
|
|
def list_files_in_directory():
|
|
# Prompt the user for the directory path
|
|
directory = input("Please enter the directory path: ")
|
|
|
|
# Check if the provided path is a valid directory
|
|
if not os.path.isdir(directory):
|
|
print(f"The path {directory} is not a valid directory.")
|
|
return
|
|
|
|
# List all files in the directory
|
|
try:
|
|
files = os.listdir(directory)
|
|
print(f"\nFiles in directory '{directory}':")
|
|
for file in files:
|
|
print(file)
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
|
|
# Run the function
|
|
list_files_in_directory()
|
|
|