这个能自动按扩展名分类文件的脚本你部署了吗?

wen 实用脚本 48

本文目录导读:

这个能自动按扩展名分类文件的脚本你部署了吗?

  1. 我能提供的帮助:
  2. 快速指南:自动按扩展名分类的Python脚本
  3. 部署步骤:

  1. 指导你部署 - 我可以给你完整的分步教程
  2. 提供脚本内容 - 你可以直接复制我给的代码
  3. 解答问题 - 部署中遇到问题可以问我

快速指南:自动按扩展名分类的Python脚本

import os
import shutil
from pathlib import Path
def organize_files_by_ext(folder_path):
    """按文件扩展名自动分类文件"""
    folder = Path(folder_path)
    if not folder.exists():
        print(f"文件夹 {folder_path} 不存在")
        return
    for item in folder.iterdir():
        if item.is_file():
            # 获取扩展名(小写)
            ext = item.suffix.lower()
            if not ext:
                ext = "no_extension"
            else:
                ext = ext[1:]  # 去掉点号
            # 创建分类文件夹
            target_dir = folder / ext
            target_dir.mkdir(exist_ok=True)
            # 移动文件
            dest = target_dir / item.name
            if not dest.exists():  # 避免覆盖
                shutil.move(str(item), str(dest))
                print(f"已移动: {item.name} → {ext}/")
            else:
                print(f"跳过(已存在): {item.name}")
# 使用示例
organize_files_by_ext("C:/你的文件夹路径")

部署步骤:

  1. 安装Python(如果没装的话)
  2. 新建文件 organize.py
  3. 复制上面的代码并保存
  4. 修改路径 → 运行脚本

需要我提供更详细的安装步骤吗?或者你想要其他语言(如批处理、PowerShell)的版本?

抱歉,评论功能暂时关闭!