Khalsa Labs

List Files and Folders With Python

Easily List Files and Folders with Python from any Path of your system. The Default included module ‘OS’ in Python will greatly helpful for performing operating system level functions. OS module has many file related functions like listdir() –  for listing the contents of any Path or Dir ,which we use in the script for count and view files and folders at any path of system.

List Files and Folders With Python

Here is a small code for count and Display List of Files and Folders in Python:

import os
path = raw_input("Enter the Path: ")
lst = os.listdir(path)
total = len(lst)
print "No. of Total files and folders at ", path ," = ", total
i = raw_input("nType v and press Enter for view list nPress any other key to exit.... n")
if i=='v':
    for f in lst:
        print f

 

There are also many other powerful functions like chmod() – used for changing permissions of files and many other functions like that and some tricks can be performed by this module will be described in [button url=”http://khalsalabs.com/wallpaper-change-with-python/” size=”small” target=”self”]Wallpaper change With Python[/button]

The following two tabs change content below.
Python Developer and DIY lover.

want to comment ??

Your email address will not be published. Required fields are marked *