You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1012 B
28 lines
1012 B
8 months ago
|
import py_compile
|
||
|
|
||
|
py_compile.compile('f1.py')
|
||
|
py_compile.compile('f2.py')
|
||
|
|
||
|
import os
|
||
|
import shutil
|
||
|
|
||
|
# 设置源目录和目标目录
|
||
|
source_dir = os.path.join(os.path.dirname(__file__), '__pycache__') # 当前目录下的 __pycache__ 目录
|
||
|
target_dir = os.path.join(os.path.dirname(__file__), '..', 'plugins') # 上一级目录下的 plugins 目录
|
||
|
|
||
|
# 确保目标目录存在
|
||
|
os.makedirs(target_dir, exist_ok=True)
|
||
|
|
||
|
# 遍历源目录中的所有 .pyc 文件
|
||
|
for filename in os.listdir(source_dir):
|
||
|
if filename.endswith('.pyc'):
|
||
|
# 提取文件名的前两个字符
|
||
|
new_filename = filename[:2]
|
||
|
# 构建源文件和目标文件的完整路径
|
||
|
source_file = os.path.join(source_dir, filename)
|
||
|
target_file = os.path.join(target_dir, new_filename + '.pyc')
|
||
|
# 拷贝文件
|
||
|
shutil.copyfile(source_file, target_file)
|
||
|
# 删除原始文件
|
||
|
os.remove(source_file)
|
||
|
print(f"Copied {filename} to {target_file} and removed original file.")
|