Scenario:
Download multiple folders is a compressed package, unzip Each folder has a link to a website promotion, you want to batch delete the file
Use of the environment: win7, python3.6
Code:
OS Import DEF readFilename (file_dir): for the root, dirs, in os.walk Files (file_dir): return Files, dirs, the root DEF the deletefiles (Files, dirs, the root): for I in Files: IF I in del_file_list: Print ( "-" * 20) Print ( 'the delete:% S'% os.path.join (root, i), i) # View specific path delete files os.remove (os.path.join (root, i)) for dirs in J: Fi, DI, RO = readFilename (the root + "\\" + J) the deletefiles (Fi, DI, RO) IF the __name__ == '__main__': wanted_del_file_dir = u'd: \\ \\ S15django temporary 00python 'the most superior batch file # to delete the folder files, dirs, root = readFilename ( wanted_del_file_dir) del_file_list = [' Baidu cloud SVIP free long-term use .url ', 'I love this course of study it offers .url', 'HD electronic books .url', 'more excellent tutorial .url', 'must-see download .txt', ] # Set the file you want to delete the deletefiles (Files, dirs, root) Print ( 'delete completed!')