1 defmkdir (title):#create a basic format for multilevel catalogs2Path = Title.strip ()#Make sure you don't include spaces3Isexists = Os.path.exists ('e:\\py\\xmly\\'+path)#parameter is absolute path4 #R ' E:\py\xmly\\ ' R to escape function (must have double slash at the end) equal to ' e:\\py\\xmly\\ ' need to escape the character before adding \5 #The os.path.join (R ' E:\xmly\py\\ ', path) function is to stitch the path, or ' e:\\py\\xmly\\ ' +path6 if notisexists:7Os.makedirs ('e:\\py\\xmly\\'+path)8 #the difference between os.mkdir (path) and Os.makedirs (path):9 #the biggest differences between the two functions are:Ten #when the parent directory does not exist One #Os.mkdir (path) is not created, A #os.makedirs (Path) creates the parent directory - Print 'Create Directory * * *'+title+'* * * success! ' - returnTrue#Do not Add or error, do not know what to use, or add it the Else: - Print 'Directory * * *'+title+'* * * already exists! '. Format () - returnFalse#Ibid. true
Start importing the OS module
Switch to a path using method Os.chdir (path)
Python creates a basic format for multilevel catalogs