Skip to content

Instantly share code, notes, and snippets.

@somada141
Created March 9, 2015 02:45
Show Gist options
  • Save somada141/d994c35dc306c9e93d1a to your computer and use it in GitHub Desktop.
Save somada141/d994c35dc306c9e93d1a to your computer and use it in GitHub Desktop.
List all files in the current working directory with Python #python #os

This can be done with the listdir() and getcwd() methods of the os module:

  • os.listdir("path"): lists all files and directories under path which is provided as a string
  • os.getcwd(): returns the full path to the current working directory

usage:

import os
os.listdir(os.getcwd())

The above will return a list object with all file/directory names under the current working directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment