Python creates a basic format for multilevel catalogs

Source: Internet
Author: User
Tags create directory

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.