当前位置:网站首页>实现按照序号命名的txt文件由后往前递补重命名文件
实现按照序号命名的txt文件由后往前递补重命名文件
2022-07-27 20:45:00 【猴哥儿你真了不得】
实现按照序号的命名的txt文件由后往前递补重命名文件
例如现拥有四个文件:
A_1.txt A_3.txt A_4.txt A_5.txt
实现变成A_1.txt~A_4.txt
3->2 4->3 5->4
import pathlib
import os
def fill_sequence(input_path, keywords_list):
for kw in keywords_list:
print(f'Fill sequence {
enu + 1}/{
(len(keywords_list))} keyword:', kw)
txtdir_path = input_path + '/' + kw
all_txt_file = list(pathlib.Path(txtdir_path).glob('**/*.txt'))
for i in range(len(all_txt_file)):
input_file = txtdir_path + f'/{
kw}_{
i + 1}.txt'
# input_filename = f'{kw}_{i + 1}.txt'
if not os.path.exists(input_file):
for add in range(2, 50):
next_file = txtdir_path + f'/{
kw}_{
i + add}.txt'
# next_filename = f'{kw}_{i + add}.txt'
if os.path.exists(next_file):
os.rename(next_file, input_file)
break
if __name__ == '__main__':
input_path = ""
keywords_list = ['A', 'B', 'C']
fill_sequence(input_path, keywords_list)
边栏推荐
- Introduction to the paper | language model for long text under transformer architecture
- 寻找和利用 XXE – XML 外部实体注入
- Safety foundation 2
- 三次握手的Socket交互流程
- Exercise --- BFS
- 毕设-基于SSM高校后勤管理系统
- What is the MySQL data storage method?
- 携手长江存储,江波龙推出全球最小扩展卡
- Read an article to understand artificial neural network
- 营收、利润两位数增长,华润怡宝悄悄打造了这些过亿新品
猜你喜欢
![[soft test software evaluator] 2014 comprehensive knowledge over the years](/img/85/46c8fc696ae5249a9aca22b50493f0.jpg)
[soft test software evaluator] 2014 comprehensive knowledge over the years

【数字识别】基于Hopfield神经网络识别0-9数字附Matlab代码

Nature综述:微生物群落形成过程中的优先效应

评价自动化测试优劣的隐性指标

See how Gan controls the image generation style step by step? Explain the evolution process of stylegan in detail

用户画像在科技期刊微信公众号精准推送中的应用

Lianmai live broadcast system software - voice chat system

C#委托用法--控制台项目,通过委托实现事件

【 图像去雾】基于暗通道和非均值滤波实现图像去雾附matlab代码

【数字识别】基于知识库实现手写体数字识别附matlab代码
随机推荐
Exercise --- BFS
习题 --- BFS
使用灰度滤镜
置信区间之正态
NDK 系列(6):说一下注册 JNI 函数的方式和时机
技术认证 | 图扑软件携手华为云再创合作共赢新局面
[image defogging] image defogging based on dark channel and non-mean filtering with matlab code
疫情之下,台积电一季度增长超预期,7nm占比35%!二季度或创新高
四次挥手的Socket交互流程
小程序容器技术超有料,可以让移动研发效率大幅提升
Library management system based on SSM framework
面试官:说一下网络数据传输的具体流程
进程同步的方式有哪些?
台积电3nm细节曝光:晶体管密度高达2.5亿个/mm²,性能及能效大幅提升
[stonedb fault diagnosis] database instance crash
携手长江存储,江波龙推出全球最小扩展卡
The wechat installation package has expanded 575 times in 11 years, and the up owner: "98% of the documents are garbage"; Apple App store was exposed to a large number of pornographic apps; Four techn
Safety foundation 2
2022/7/26
看GAN如何一步步控制图像生成风格?详解StyleGAN进化过程