Python allows you to find the characters in the system disk.

Source: Internet
Author: User
Tags decimal to binary

Python allows you to find the characters in the system disk.

This example describes the characters that need to be searched in the Python system disk. Share it with you for your reference. The details are as follows:

'''Created on 2011-7-13 @ author: 123 ''' import OS # Save the current disk def existdisk (): curdisks = [] allDisks = ['C: ', 'd: ', 'e:', 'f: ', 'G:', 'H: ',' I: ', 'J:', 'K :', \ 'l: ','m:', 'N': ', 'O:', 'P: ', 'q:', 'r: ','s: ', 't:', \ 'U:', 'v: ', 'W:', 'x: ', 'y:', 'z :', 'A: ',' B: '] for disk in allDisks: if OS. path. exists (disk): curdisks. append (disk) return curdisks # The directory contains the searched character def SearchDirFile (path, src): if not OS. path. ex Ists (path): print "% s path does not exist" % path for root, dirs, files in OS. walk (path, True): if-1! = Root. find (src): # Whether the character print root for item in files: path = OS. path. join (root, item) if-1 exists in the path name! = Path. find (src): # print path of the character to be searched in the file list # find the def SearchFile (path, src) in the file content: if not OS. path. exists (path): print "% s path does not exist" % path for root, dirs, files in OS. walk (path, True): for item in files: path = OS. path. join (root, item) try: f = open (path, 'R') for eachline in f. readlines (): if-1! = Eachline. find (src): # whether the text content contains the print path f. close () break failed T: pass # Check whether the def SearchAllDirFile (src): curdisks = existdisk () for disk in curdisks is found in all the current disk directories: disk = disk + '\' SearchDirFile (disk, src) print "complete search" # Find whether all files in the current disk directory contain the characters def SearchALLFile (src ): curdisks = existdisk () for disk in curdisks: disk = disk + "\" SearchFile (disk, src) print "complete search" SearchALLFile ('convert decimal to binary ')

I hope this article will help you with Python programming.

Related Article

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.