Files
nanocode/create_dirs.py
T
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

27 lines
875 B
Python

#!/usr/bin/env python3
import os
import shutil
# 清理旧目录
target_dir = "/home/ubuntu/nanocode/it_automation"
if os.path.exists(target_dir):
# 只删除空目录
try:
os.rmdir(target_dir)
print(f"已删除空目录: {target_dir}")
except OSError:
print(f"目录非空,跳过删除: {target_dir}")
# 创建新目录结构
os.makedirs(os.path.join(target_dir, "scripts"), exist_ok=True)
os.makedirs(os.path.join(target_dir, "config_templates"), exist_ok=True)
os.makedirs(os.path.join(target_dir, "docs"), exist_ok=True)
print("目录结构创建成功:")
for root, dirs, files in os.walk(target_dir):
level = root.replace(target_dir, '').count(os.sep)
indent = ' ' * 2 * level
print(f'{indent}{os.path.basename(root)}/')
subindent = ' ' * 2 * (level + 1)
for file in files:
print(f'{subindent}{file}')