
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to list down all the files alphabetically using Python?
You can call the os.listdir function to get the list of the directory contents and use the sorted function to sort this list.
For example
>>> import os >>> list_dir = os.listdir('.') >>> list_dir = [f.lower() for f in list_dir] # Convert to lower case >>> sorted(list_dir) ['dlls', 'doc', 'etc', 'include', 'lib', 'libs', 'license.txt', 'news.txt', 'python.exe', 'pythonw.exe', 'readme.txt', 'scripts', 'share', 'tcl', 'tools', 'w9xpopen.exe']
- Related Questions & Answers
- How to list down all the files available in a directory using C#?
- How to list down all the cookies by name using JavaScript?
- How to close all the opened files using Python?
- How to touch all the files recursively using Python?
- How to list down all the running queries in MySQL?
- How to list all files in a directory using Java?
- How to list all files (only) from a directory using Java?
- Learn how to find and list down recently modified files in linux
- Python program to sort a list of tuples alphabetically
- How to list down all the plug-in installed in your browser?
- How to list down all the available commands and aliases on Linux?
- List down all the Tables in a MySQL Database
- How do I list all files of a directory in Python?
- How to display all items in the list in the drop down in Selenium?
- How to extract all the .txt files from a zip file using Python?
Advertisements