The USB flash drive was poisoned, and there was an extra .lnk file in every folder inside the USB flash drive. Virgo was at it again, and couldn't stand it, so I wrote a script to delete all the .lnk files.
Recursive Deletion of Multi-Level Catalogs
import os n = 0 for root, dirs, files in ('./'): for name in files: if((".lnk")): n += 1 print(n) ((root, name))
Save this script as and put it in the root directory of the USB drive, cd into the root directory of the USB drive and:
python
It is possible to delete all .lnk files, including subfolders, from the USB flash drive.
Here you only need to specify only the parameters of (), . /that is, the current directory, so that traversal can traverse all directories and files under the specified path, including the case of multi-level directories. .
Honestly, it was a great inner satisfaction to finally see 20+ lnk files deleted!
Delete the specified file in the current directory
import os n = 0 for root, dirs, files in ('.'): for name in files: if("WeChat Screenshot"in name): n += 1 print(n) print(name) ((root, name))
The above code will delete all files in the current folder that contain "WeChat Screenshot" in the file name.
This python3 traversal to delete files with specific suffixes is all I have to share with you.