Skip to content

Instantly share code, notes, and snippets.

@anmolj7
Last active December 3, 2019 09:40
Show Gist options
  • Save anmolj7/60515453f385366d28468615096d59a8 to your computer and use it in GitHub Desktop.
Save anmolj7/60515453f385366d28468615096d59a8 to your computer and use it in GitHub Desktop.
import os
print("Python Program to print list the files in a directory.")
Direc = input(r"Enter the path of the folder: ")
print(f"Files in the directory: {Direc}")
files = os.listdir(Direc)
files = [f for f in files if os.path.isfile(Direc+'/'+f)] #Filtering only the files.
print(*files, sep="\n")
#os.getcwd() gives us the current working directory, and os.listdir lists the director
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment