use os.walk Traverse all file names , There is ‘.pages’ File path , And use os.remove Delete these files
# Character painting comes from this website , Rich font types
#http://www.network-science.de/ascii/
""" _ _ ____ _____ _____ ______ _____ | \ | | / __ \ | __ \ /\ / ____|| ____| / ____| | \| || | | || |__) |/ \ | | __ | |__ | (___ | . ` || | | || ___// /\ \ | | |_ || __| \___ \ | |\ || |__| || | / ____ \| |__| || |____ ____) | |_| \_| \____/ |_| /_/ \_\\_____||______||_____/ """
import os
file_dir = '/Users' # Start from this path to find the file
f = [] # Storage file name
r = [] # Storage file path
for root, dirs, files in os.walk(file_dir): # Traverse the file names and paths of all files
for name in files: # Traverse the file name , Yes .pages Just write it down
if '.pages' in name:
f.append(name)
r.append(root)
print('Found %d sneaky .pages files in your computer'%len(f))
if len(f) != 0:
print('They are: ', f)
# Deleting the comments in the next few lines will directly delete these files
# i = 0
# for i in range(0, len(f)):
# os.remove(r[i]+'//'+f[i]) # The first slash indicates that the second slash is not a special character
# print('Successfully deleted '+f[i])
For special reasons , I am extremely disgusted with the apple system pages file , So just write a program to practice .
The code applies to mac System .windows System handle file_dir Of ’/Users’ Change to C disc D The plates are the same , The later path representation may also need to be adjusted .
use pyinstaller/py2exe Wait for the package to convert the program into .exe file . Change the matching condition of the file name you want to delete , Put it in U pan , Add one .inf file , Can let the computer insert U This program runs automatically when the disk , Delete file .( It is strongly recommended that you do not try ! Those who cause losses should bear their own responsibility !!)