python批量修改文件程序代码
来源:互联网 发布:js a href 赋值 编辑:程序博客网 时间:2024/05/17 23:46
1:首先我们来介绍几个函数
os.listdir(path);会得到这个给定的目录中的所有东西——文件和目录
os是python内置的模块叫做os操作系统(operating system)的简称。
rename(src,dst):给文件或文件夹改名(可以改路径,但是不能覆盖目标文件)
string.translate()requires a dict that maps unicode ordinals to other unicode oridinals (or None if you want to remove the character).
例如:
old_string = "file52.txt"to_remove = "0123456789"table = {ord(char): None for char in to_remove}new_string = old_string.translate(table)assert new_string == "file.txt"
However, there is simpler way of making a table though, by using the str.maketrans function. It can take a variety of arguments, but you want the three arg form. We ignore the first two args as they are for mapping characters to other characters. The third arg is characters you wish to remove.
old_string = "file52.txt"to_remove = "0123456789"table = str.maketrans("", "", to_remove)new_string = old_string.translate(table)assert new_string == "file.txt"
2:因此到了这里,我们可以写个给批量文件的文件名去掉数字的程序
当我们运行程序时确发现控制台出现了这样的结果。
问题是出在了第九行,用os.getcwd()函数得到当前工作目录。
参考链接:
python官方API os模块
translate() takes exactly one argument (2 given) in python error
- python批量修改文件程序代码
- Python 批量修改文件
- python批量修改文件
- python 批量修改文件后缀
- 使用python批量修改文件的后缀
- python实现批量修改文件扩展名
- Python 批量修改文件内关键字
- Python批量修改文件后缀名,文件内…
- Python批量修改文件名
- python 批量修改文件名
- python 批量修改密码
- Python批量修改文件名
- python批量修改文件名
- python批量修改文件名
- python 批量修改文件名
- python批量修改编码
- python批量修改文件名
- python 批量修改图片大小
- 手机车牌识别二次开发包
- Poj-3696 The Luckiest number(数论)
- 8.8.1
- 多线程相关
- luogu1019【2000提高】单词接龙(字符串+dfs)
- python批量修改文件程序代码
- 用STS工具创建springboot+nutz+beetl案例
- kafka入门:简介、使用场景、设计原理、主要配置及集群搭建(转)
- Redis新手快速入门(二)
- Super Jumping! Jumping! Jumping! (前面那篇文章因为格式问题删了重写了一篇
- 338. Counting Bits
- Swift 学习笔记(二)
- 文章标题
- 二叉树面试题总结(Java)