Python development _glob

'''
    In thepythonIn the, globModule is used to find the matching files
    In the search condition, need to use matching rules in Unix shell: 

       *    :   Matching all
       ?    :   Matching a character
       *Such as: matching.: [hello.txt,cat.xls,xxx234s.doc]
       ?Such as: matching.: [1.txt,h.py]
       ?.gif: match: [x.gif,2.gif]
    Can refer to: fnmatch
    If no matching, glob.glob (path) returns an empty list:[]
'''

The following is my demo

Effect of operation:

=============================================

Part of the code:

=============================================

 1 #python glob
 2 
 3 '''
 4     In Python, the glob module is used to find the matching files
 5     In the search condition, need to use matching rules in Unix shell: 
 6 
 7        *    :   Matching all
 8        ?    :   Matching a character
 9        *Such as: matching.: [hello.txt,cat.xls,xxx234s.doc]
10        ?Such as: matching.: [1.txt,h.py]
11        ?.gif: match: [x.gif,2.gif]
12 
13     If no matching, glob.glob (path) returns an empty list:[]
14 '''
15 import glob
16 
17 def get_all():
18     '''Access to the directory [c:\tmp] all of the following documents'''
19     return glob.glob('c:\\tmp\\*.*')
20 
21 def get_my_file():
22     '''Access to the directory [c:\tmp] under the file name is 4 characters in the file'''
23     return glob.glob('c:\\tmp\\????.txt')
24 
25 def get_batch_file():
26     '''Access to files with the extension \'.txt\'directory under [c:\tmp]'''
27     return glob.glob('c:\\tmp\\*.txt')
28 
29 def main():
30     print('Access to the directory [c:\tmp] all of the following documents: ')
31     tem_files = get_all()
32     print(tem_files)
33     print('Access to the directory [c:\tmp] under the file name is 4 characters in the file: ')
34     tem_files = get_my_file()
35     print(tem_files)
36     print('Access to files with the extension \'.txt\'directory under [c:\tmp]: ')
37     tem_files = get_batch_file()
38     print(tem_files)
39 
40 if __name__ == '__main__':
41     main()

Posted by Ansel at November 17, 2013 - 5:12 PM