Recent projects almost, back to learn the basics of knowledge, today saw, Glob module feel very good, write to Memo.
Glob module can help us to quickly find the file of the system, or view, not to call its own OS, module, quick and easy, support simple regular: Find files only use three matches: "*", "?", "[]". "*" matches 0 or more characters; "?" Matches a single character; "[]" matches a character in a specified range, such as: [0-9] matches a number.
Examples of:>>> import glob>>> print Glob.glob ('/tmp/* ') ['/tmp/xiaoluo.txt ', '/tmp/yum.log ', '/tmp/ TMPT4PKWG ', '/tmp/paramiko1.py ', '/tmp/sess_fa2cc319aa24dc8671e9cb231253d118 ', '/tmp/mysql.sock ', '/tmp/pear ', '/ tmp/sess_6c9be7618e7d3743a1767dc523ad8060 ']>>> print glob.glob ('/tmp/*.txt ') ['/tmp/xiaoluo.txt '] simply write a function , when entering a value, list all the files inside: #!/usr/bin/env python#coding=utf-8import globdef Get_dir (file_list): Return Glob.glob ('%s/* '% ( file_list)) If __name__ = = ' __main__ ': Print Get_dir ('/tmp ') so we can call this module directly when we use it to print the files in this directory.
This article is from the "Little Luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1618942
Application of Python Glob module