惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
博客园 - 聂微东
有赞技术团队
有赞技术团队
The Cloudflare Blog
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
T
The Blog of Author Tim Ferriss
D
Docker
L
LangChain Blog
Vercel News
Vercel News
C
Check Point Blog
博客园 - Franky
博客园 - 三生石上(FineUI控件)
Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
人人都是产品经理
人人都是产品经理

博客园 - 狗狗听话

SpringBoot学习之缓存@Caching, @Cacheable,@CacheEvict Java学习之 EasyExcel Java学习之LocalDateTime, LocalDate, LocalTime SpringBoot学习之JPA设置多个主键的方法 Python使用psycopg2的copy_from方法高效的大量数据批量导入 SpringBoot学习之文件上传(利用postman测试) SpringBoot学习之文件上传,下载 Python常用的语法糖 Python学习之datetime Java学习之 stream 常用方法 SpringBoot学习之使用idea打包jar文件 React学习之数组 Java学习之日期时间转换 Java读取execl 利用JDBC插入Postgresql简单示例 Springboot中项目启动加载的几种方式 Java selenium实现浏览器ctrl + s功能 Macbook pro 安装Redis Macbook pro 打开pgAmin报错 SpringBoot学习之任务定时器 关于git rebase中的一些问题:Git报错“no branch, rebasing master”
python在某个目录下的查找指定文件夹
狗狗听话 · 2026-04-09 · via 博客园 - 狗狗听话
import shutil
from pathlib import Path

file_filter = ["200818", "00200258", "200555", "200358"]
source_path = "/Users/shaomengchen/source" #源路径
target_path = "/Users/shaomengchen/backup" #目标路径

source = Path(source_path)
target = Path(target_path)

# 合并正则:002开头8位 或 2开头6位
pattern = r'^(002\d{5}|2\d{5})$'

for folder in source.rglob('*'):
if folder.is_dir() and (folder.name in file_filter or f'00{folder.name}' in file_filter):
print(f'目录路径:{folder.absolute()},目录文件数:{sum(1 for item in folder.iterdir() if item.is_file())}')
#print(f'{folder.absolute()}/{folder.name}, {target.absolute()}/{folder.name}')
shutil.copytree(f'{folder.absolute()}',f'{target.absolute()}/{folder.name}', dirs_exist_ok=True)