June 15, 2014

Python – Navigation directories

If you want to do pwd, cd, and ls, then you need to import the os module first:


You can find all my latest posts on medium.

import os

Now we have the following functions:

=>=>=> os.getcwd() # equivalent to pwd
=>=>=> os.chdir("C:/") # equivalent to cd
=>=>=> os.listdir() # equivalent to ls
[‘$AVG’, ‘$Recycle.Bin’, ‘Documents and Settings’, ‘hiberfil.sys’, ‘inetpub’, ‘Intel’, ‘NV
IDIA’, ‘pagefile.sys’, ‘PerfLogs’, ‘Prey’, ‘Program Files’, ‘Program Files (x86)’, ‘Progra
mData’, ‘Python34’, ‘Recovery’, ‘System Volume Information’, ‘Temp’, ‘Users’, ‘Windows’]