Python 文件重命名工具代码
发布时间:2022-09-25 05:15:32
标签:Python,文件重命名
#Filename:brn.py
#Description: batch replace certain words in file names
#Use to bat rename the file in a dir(modify the suffix from a to b) for Windows Vista OS
import sys
import os
import fnmatch
import re
#parse params
p=input("Please input work directory(current path for enter):")
if p=='\r':
p='.'
p=p.rstrip('\r')
print (p)
while not os.path.exists(p):
print (p+' is not existed.Please input the work directory:')
p=input("Please input work directory(current path for enter):")
s=input("Please enter the words which need be modified(must):")
while s=='\r':
s=input("Please enter the words which need be replaced(must):")
s=s.rstrip('\r')
d=input("Please enter the words which want to change to(must):")
while d=='\r':
d=input("Please enter the words which want to change to(must):")
d=d.rstrip('\r')
try:
sure=input("Are you sure to rename the file named *"+s+"*"+" to *"+d+"*"+" in directory "+p+"? y/n:")
sure=sure.rstrip('\r')
if sure!='y':
print ("Cancel")
else:
for root, dirs, files in os.walk(p, True):
for file in files:
print (os.path.join(root,file))
if os.path.isfile(os.path.join(root,file)):#Only file is file,not a dir ,do this
if fnmatch.fnmatch(file, '*'+s+'*'):
f=str(file).replace(s,d)
if p=='.':
command='move '+str(file)+" "+f
else:
command="move "+os.path.join(root,file)+" "+os.path.join(root,f)
print (command)
if os.system(command)==0:#do actual rename
print ("Rename "+str(file)+" to "+f+" success")
else:
print ("Rename "+str(file)+" to "+f+" failed")
#else:
#print str(file)+" is a directory.omit"
except IndexError:
print (IndexError.message)
0
投稿
猜你喜欢
- 本文主要是用PyTorch来实现一个简单的回归任务。 编辑器:spyder1.引入相应的包及生成伪数据import torchimport
- 到了今天,数据库已经成了网站的灵魂,可以说,没有对数据进行集中管理就算不上是一个真正的网站。而ASP加数据库,更成了主流中的主流,网站里的用
- 在本项目中,将会用Keras来搭建一个稍微复杂的CNN模型来破解以上的验证码。验证码如下: 利用Keras可以快速方便地搭建CNN
- 这篇博客主要是为了学习Python和PyQt,因为对棋类游戏比较热衷,所以从规则较简单的五子棋入手,利用PyQt5实现图形界面,做一个可以进
- 目录介绍:原理:1.标准import2.reload函数实现:总结:介绍:热更新,就是在服务器不重启的的情况下,对游戏增加新的功能或者修复出
- K最近邻属于一种分类算法,他的解释最容易,近朱者赤,近墨者黑,我们想看一个人是什么样的,看他的朋友是什么样的就可以了。当然其他还牵着到,看哪
- NumPy 是一个Python 库,用于 Python 编程中的科学计算。在本教程中,你将学习如何在 NumPy 数组上以多种方式添加、删除
- CACHE_BACKEND参数每个缓存后端都可能使用参数。 它们在CACHE_BACKEND设置中以查询字符串形式给出。 有效参数如下:&n
- 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各
- python数据结构之 列表和元组序列:序列是一种数据结构,它包含的元素都进行了编号(从0开始)。典型的序列包括列表、字符串和元组。其中,列
- python处理数据时,可以将数据保存至excel文件中,此处安利一个python利器,openpyxl,可以自动化处理数据值excel表格
- Session StaticObjects 集合StaticObjects 集合包含 Session 对象范围中用 <OBJECT&g
- 假设我们有一个数据集,列名叫status下面有100万的数据,其中包装 “HUMAN_REFUSE”,”SYS_REFUSE”,”HUMAN
- 开始码代码之前,我们先来了解一下三种邮件服务协议:1、SMTP协议SMTP(Simple Mail Transfer Protocol),即
- 一、求算术平方根a=x=int(raw_input('Enter a number:'))if x >= :while
- 可以使用python中的sys模块的getrefcount()方法来获取对象引用的个数。具体可以看以下的实例:import sys # 首先
- 各位大哥: 在javascript中如何取整?比如: var
- 使用access数据库时可能用到的数据转换:类型转换涵数:函数 返回类型 expression 参数范围CBool Boolean 任何有效
- Numpy、Pandas是Python数据处理中经常用到的两个框架,都是采用C语言编写,所以运算速度快。Matplotlib是Python的
- 本文实例讲述了Python线程threading模块用法。分享给大家供大家参考,具体如下:threading-更高级别的线程接口源代码:Li