Python 3.5 deleting specified files recursively

Starting with Python 3.5, glob module supports the '**' directive, which matches any files and zero or more directories or subdirectories if the 'recursive' is set as True. 

The following example shows how to delete the files of which the filename contains '(1)':

import os  
import glob  

for filename in glob.iglob('C:\\test\\**\\*', recursive=True):
	if ('(1)' in filename and os.path.isfile(filename)):
		print(filename)
		os.remove(filename)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章