Tuesday, September 22, 2009

python - os module and working directory

import os 

# curdir attribute lists the current directory
# which is always '.' .... which means...right here
print os.curdir

#output:
# .

# to see what the path to the curdir
print os.path.abspath(os.path.curdir)

#output
# C:\Documents and Settings\steve\My Documents\python

# and then to see what files are in the curdir
print os.listdir(os.curdir)
#or
print os.listdir(os.path.abspath(os.path.curdir))

# output for either listdir
#['colormaker.py', 'createThumbnail.py', 'strFunctions.py', 'pycolor.py']

No comments:

Post a Comment