11 Star 109 Fork 17

yeytytytytyytyt / AirDropPlus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils.py 796 Bytes
一键复制 编辑 原始数据 按行查看 历史
123123 提交于 2024-05-14 08:31 . 使用secure_filename校验文件名
import os
import re
import psutil
import imghdr
def avoid_duplicate_filename(save_path, filename):
base_filename, extension = os.path.splitext(filename)
counter = 1
while os.path.exists(os.path.join(save_path, filename)):
filename = f"{base_filename} ({counter}){extension}"
counter += 1
return filename
def is_program_running():
program_name = "AirDropPlus.exe"
count: int = 0
for process in psutil.process_iter((['name'])):
if process.info['name'] == program_name:
count += 1
if count >= 2: # 自身也占用一个
return True
return False
def is_image_file(file_path):
image_type = imghdr.what(file_path)
if image_type is not None:
return True
else:
return False
Python
1
https://gitee.com/yeytytytytyytyt/air-drop-plus.git
git@gitee.com:yeytytytytyytyt/air-drop-plus.git
yeytytytytyytyt
air-drop-plus
AirDropPlus
master

搜索帮助