Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图构建一个脚本来自动重命名文件并且失败了,所以如果有人可以帮助......
在同一个文件夹中,我的文件名如下:
exemple_012345-0abc1def.txt exemple_012345-0abc1def.config.txt
我想删除第一个下划线(包括)和第一个点之间的所有内容,以便我得到如下文件名:
exemple.txt exemple.config.txt
谢谢
这可以在 python 中轻松完成。我不确定这是否可以与 windows 中的 python 完美配合。
import os for root, dirs, files in os.walk('.'): for fname in files: x = fname.index('_') y = fname.index('.') substr = fname[:x] + fname[y:] os.rename(fname, substr)