python批量修改文件名

6-08 2,656 views

import os
import fnmatch
#path写路径,fnexp写文件后缀.
def iterfindfiles(path, fnexp):
for root, dirs, files in os.walk(path):
for filename in fnmatch.filter(files, fnexp):
yield os.path.join(root, filename)

for filename in iterfindfiles(r"c:\dianzi_book_cate", "*.png"):
#获取文件前缀,和后缀
math = os.path.splitext(filename)[0][20:]
prepath = os.path.splitext(filename)[0][:20]
#重命名
os.rename(filename,prepath+'2015-'+math+'.png')

python清空文件夹下log文件

#!/usr/bin/python import os import sys files_list = [] def print_files(path): lsdir = os.listdir(path) dirs = [i for i in lsdir if os.path...

阅读全文

python paramiko(SFTP) 相关文档

python paramiko SFTP文档地址: http://docs.paramiko.org/en/2.4/api/sftp.html import paramiko host = "THEHOST.com" #...

阅读全文

python 执行cmd命令并获取pid

process = subprocess.Popen('cmd命令') pid = process.pid print(pid)

阅读全文

欢迎留言