当前位置:网站首页>对文件夹下所有的文件一键改名
对文件夹下所有的文件一键改名
2022-06-21 11:29:00 【精神抖擞王大鹏】
背景
在下云盘课程时,发现很多课程后缀都会加一些特殊标志,感觉很影响结构化的观感,同时如果资料有代码的话,这种标识也会影响代码直接打开。因此做了一个简单的一键遍历程序,并打包为exe。
思路
- 给定一个父目录的文件路径,及要删除的文件名内容;
- 不断向下扫描到根文件名,再对根文件名进行rename;
代码
import os
import sys
def get_files(filename):
for filepath,dirnames,filenames in os.walk(filename):
for filename in filenames:
target_name = os.path.join(filepath,filename)
# print(target_name)
os.rename(target_name, target_name.replace('要去掉的内容',''))
print('处理完成')
def convert_path(path):
return path.replace(r'\/'.replace(os.sep, ''), os.sep)
if __name__ == '__main__':
filepath = r'D:\00.资料\document-master\正式课程资料'
print(convert_path(filepath))
get_files(filepath)

这样即可支持一键更换名称。
边栏推荐
猜你喜欢

A Kuan food: the battle for "the first share of convenience food" continues

电源老化测试系统定制|充电桩自动化测试系统NSAT-8000概述

15+ urban road element segmentation application, this segmentation model is enough!
The first question of leetcode -- sum of two numbers

Break down tasks

2022危险化学品经营单位安全管理人员特种作业证考试题库及在线模拟考试

高性能并行编程与优化 | 第01讲回家作业

适配器电源自动测试设备|充电器ATE测试系统NSAT-8000介绍

Citus 11 for Postgres is completely open source and can be queried from any node (citus official blog)

转赠券发放倒计时!星际口袋转赠规则抢先看
随机推荐
使用赞美提高绩效
DevSecOps:应当做好的十件事
请教下。使用mysql-cdc需要mysql启用什么设置或者功能的保障么,还是说只要有mysql的i
There are obvious signs of oversupply of chips, ASML is no longer a pastry, and investment institutions are shorting on a large scale
SSD [target detection]
數據可視化入門
5 best practices for perfect security code auditing
Flink tuning (I) resource tuning and back pressure analysis
Kotlin - I/O流
服务器安全审计系统设计与实现
分解任务
Never ending database injection attack and defense
永不落幕的数据库注入攻防
中国企业海外业务DDoS防护探索
qt对sqlite数据库多线程的操作
Design and implementation of server security audit system
2022 special operation certificate examination question bank and online simulation examination for safety management personnel of hazardous chemical business units
You must get started with boost
【100个 Unity踩坑小知识点】| Unity中的 碰撞盒检测 Physics.OverlapBox、OverlapCaps
Flynk CDC reads MySQL 8 hours late. Set the servertimezone parameter