python 查找文件夾下所有文件 實現代碼
更新時間:2009年07月01日 00:48:05 作者:
python 查找文件夾下所有文件,需要的朋友可以參考下。
復制代碼 代碼如下:
def find_file_by_pattern(pattern='.*', base=".", circle=True):
'''''查找給定文件夾下面所有 '''
re_file = re.compile(pattern)
if base == ".":
base = os.getcwd()
final_file_list = []
print base
cur_list = os.listdir(base)
for item in cur_list:
if item == ".svn":
continue
full_path = os.path.join(base, item)
if full_path.endswith(".doc") or \
full_path.endswith(".bmp") or \
full_path.endswith(".wpt") or \
full_path.endswith(".dot"):
continue
# print full_path
bfile = os.path.isfile(item)
if os.path.isfile(full_path):
if re_file.search(full_path):
final_file_list.append(full_path)
else:
final_file_list += find_file_by_pattern(pattern, full_path)
return final_file_list
相關文章
Python read函數按字節(jié)(字符)讀取文件的實現
這篇文章主要介紹了Python read函數按字節(jié)(字符)讀取文件的實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07