3. Directory Details
Methods for traversing directories
Listing file and their information
Creating and deleting directories and files
Test to check if something is a file or directory
4. >>> import os
>>>
>>> os.getcwd()
'/home/reza/code/PYSEC101/dir'
>>>
>>>
>>>os.mkdir('class')
$ ls
Class jalase7 jalase7.py
os.rmdir()
6. >>> for item in os.listdir('.'):
... if os.path.isfile(item):
... print item + ' is a file'
... elif os.path.isdir(item):
... print item + ' is a directory'
... else:
... print 'unknown'
...
Class is a directory
Jalase7 is a directory
jalase7.py is a file
>>>
7. This work is licensed under the Creative Commons
Attribution-NoDerivs 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/3.0/
Copyright 2013 Mohammad reza Kamalifard.
All rights reserved.