首先写出来python代码,其次把.py文件转换成exe文件,直接在windows电脑上后台运行。
代码演示:
#-*-coding:utf-8-*-
importosimporttimefromdatetimeimportdatetimeimportshutil#U盘的盘符usb_path="E:/"
#要复制到的路径save_path="D:/haha"
while(True):
ifos.path.exists(usb_path):
shutil.copytree(usb_path,os.path.join(save_path,datetime.now.strftime("%Y%m%d_%H%M%S")))
breakelse:time.sleep(10)Python文件打包成exe
1、在命令行用pip安装 pyinstaller包
Pipinstallpyinstaller
2、下载安装pyinstaler运行时所需要的windows扩展pywin32
3、在命令行中直接输入下面的指令即可
pyinstaller[opts]yourprogram.py