Portal: http://blog.csdn.net/shennongzhaizhu/article/details/51455063
In Python, you can use the Os.mkdir () function to create a directory ( create a first-level directory).
Os.mkdir (PATH)
For example, to create a hello directory under the D drive
>>> Import OS
>>> os.mkdir (' D:\hello ')
Its prototype is as follows:
Its argument path is the path to the directory to be created ( create a multilevel directory )
>>> Import OS
>>>os.makedirs (' D:\\books\\book ')
In Python, you can use the Os.rmdir () function to delete a directory.
Os.rmdir (PATH)
For example, delete the Hmm directory under the D disk.
>>> Import OS
>>> os.rmdir (' d:\hmm ')
In Python, you can use the Os.removedirs () function to delete a multilevel directory.
Os.removdirs (PATH)
>>> Import OS
>>> os.removedirs (' D:\\books\\book ')
deleting files
Its prototype is as follows:
The path to the file whose parameter path is to be deleted.
>>> Import OS
>>>os.remove (' D:\\books\\book\\book.txt ')
In Python, you can use the Os.walk () function to traverse the directory.
Os.walk (PATH)
Its parameter path is the directory to traverse, traverse Path, return an object, each of his parts is a ternary group (' Directory x ', [Directory x under directory list], directory x below the file).
 
>>> a=os.walk (' d:\\books ')
>>> def Fun ():
for I in a:
print I
>>> fun ()
(' D:\\books ', [' book '], [' Aa.txt '])
(' D:\\books\\book ', [], [])
In Python, you can use the Os.path.isdir () function to determine whether a path is a directory.
Os.path.isdir (PATH)
Its argument path is the path to be judged. Returns true if yes, otherwise false.
In Python, you can use the Os.path.isfile () function to determine whether a path is a file. Its function prototype is shown below.
Its argument path is the path to be judged. Returns true if yes, otherwise false.
Os.mkdir and Os.makedirs for OS path-related functions in Python