Listing files and directories

Listing the directory contents is easy in Python. We are going to use the os module that has a function named listdir(), which will return the names of files and directories from your working directory:

>>> os.listdir()
['Public', 'python_learning', '.ICEauthority', '.python_history', 'work', '.bashrc', 'Pictures', '.gnupg', '.cache', '.bash_logout', '.sudo_as_admin_successful', '.bash_history', '.config', '.viminfo', 'Desktop', 'Documents', 'examples.desktop', 'Videos', '.ssh', 'Templates', '.profile', 'dir', '.pam_environment', 'Downloads', '.local', '.dbus', 'Music', '.mozilla']
>>>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset