如意云-莘家小站
  • 首页
  • 友链
  • 关于
如意云-莘家小站
这是一个记录生活和技术学习的个人博客.
  1. 首页
  2. 程序开发实例
  3. 生产力小工具
  4. 正文

将众多文件夹中的文件批量一次性提取到一个文件夹

2021年8月20日 6874点热度 0人点赞 2条评论

整理群晖moments的照片,发现群晖生成了几万个文件夹,一个文件夹里若干照片,如何提取到一个文件夹?

使用了bat脚本。

新建一个文本文档,命名后缀为bat,然后粘贴以下内容,放到需要被整理目录的同级。

@echo off & setlocal enabledelayedexpansion    
if not "%~1"==":" (
md d:\new 2>nul
for /f "tokens=1*delims=/" %%i in ('"%~f0" :^|sort') do (
if /i "%%i"=="!strName!" (
set /a n+=1
copy "%%j" "d:\new\%%~ni(!n!)%%~xi"
) else (
set "n="
copy "%%j" d:\new\
)
set "strName=%%i"
)
pause
) else (
for /r %%i in (*) do echo %%~nxi/%%i
)

python版本,理论上linux也能用

# -*- coding:utf8 -*-

import os
import shutil


# From Mr.Song

source_path = os.path.abspath(r'D:\用户\OneDrive - wanin\桌面\a')
target_path = os.path.abspath(r'D:\Copied')

if not os.path.exists(target_path):
os.makedirs(target_path)

if os.path.exists(source_path):
# root 所指的是当前正在遍历的这个文件夹的本身的地址
# dirs 是一个 list,内容是该文件夹中所有的目录的名字(不包括子目录)
# files 同样是 list, 内容是该文件夹中所有的文件(不包括子目录)
for root, dirs, files in os.walk(source_path):
for file in files:
src_file = os.path.join(root, file)
shutil.copy(src_file, target_path)
print(src_file)
print('copy files finished!')
文件夹支持的命名
文件支持的命名

之后再用软媒清理大师删除一下重复的文件,搞定!

清理重复文件
清理重复文件

软媒处理不了几万张图片,会闪退,这里推荐用DoubleKiller这个软件,能处理大量文件。

DoubleKiller(topbook.cc)下载
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可
标签: 文件提取 脚本
最后更新:2024年12月27日

jiawei

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

  • Mitre

    顶一下

    2021年11月14日
    回复
    • XINJIAWEI

      @Mitre py脚本的作者来了

      2021年11月14日
      回复
  • razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
    取消回复
    • Emby
    • Synology
    • Unraid
    • 文段分享
    • 生产力小工具
    • 生活记录
    • 程序开发实例
    • 网络与系统
    • 逆向工程
    • 遇到问题

    2019-2025

    Theme Kratos Made By Seaton Jiang

    冀ICP备18022758号-2

    冀公网安备13072802000034号