Python Practice-os Module Exercise-that's the thing.

Source: Internet
Author: User

1 #edited by: Shanlong2 #applet: According to user input selection can complete the following functions:3 #Create a file, create a folder, and then create a file if the path does not exist4 #ability to view current path5 #find file names in the current directory and all subdirectories that contain the specified string6 ImportOS7 defCreatedirfile (dirname,filename):8     if(os.path.exists (Dirname) = =False):9 os.makedirs (Dirname)TenOpen (Os.path.join (dirname,filename),"W"). Close () One         Print("%s directory created complete,%s file created"%(Dirname, Filename)) A     elif(Os.path.exists (Os.path.join (dirname,filename)) = =False): -Open (Os.path.join (Dirname, Filename),"W"). Close () -         Print("%s file in%s was created"%(Dirname, Filename)) the defViewPath (): - Os.path -     Print(OS.GETCWD ()) - defGrep (FINDSTR): +      forIinchOs.walk (OS.GETCWD ()): -          forJinchI[-1]: +             if(Str (j). Find (FINDSTR) >-1): A                 Print(Os.path.join (i[0],j)) at  -p ="""1. Creating folders and Paths - 2. View the current path - 3. query file name - 4. Program Exit""" -  whileTrue: in     Print(P) -Choice = input ("Please select:") to     if(Choice = ="1"): +Dirname = input ("Dirname:") -Filename = input ("Filename:") the createdirfile (Dirname, Filename) *     elif(Choice = ="2"): $ ViewPath ()Panax Notoginseng     elif(Choice = ="3"): -Filename = input ("Filenameinstr:") the Grep (Filename) +     elif(Choice = ="4"): A exit () the     Else: +         Continue

Python Practice-os Module Exercise-that's the thing.

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.