Files
django-vue3-admin/backend/del_migrations.py
liqiang a0a7c25b18 refactor(del_migrations):增加 .venv 目录排除
- 在需要排除的目录列表中添加了 .venv,以避免删除虚拟环境目录中的迁移文件
2025-06-11 15:58:25 +08:00

15 lines
560 B
Python

# -*- coding: utf-8 -*-
import os
exclude = ["venv", ".venv"] # 需要排除的文件目录
for root, dirs, files in os.walk('.'):
dirs[:] = list(set(dirs) - set(exclude))
if 'migrations' in dirs:
dir = dirs[dirs.index('migrations')]
for root_j, dirs_j, files_j in os.walk(os.path.join(root, dir)):
for file_k in files_j:
if file_k != '__init__.py':
dst_file = os.path.join(root_j, file_k)
print('删除文件>>> ', dst_file)
os.remove(dst_file)