Python Bulk Change file name

Source: Internet
Author: User

At work, there is a situation where some apk packages are often sent by the marketing department.

But asked to change the name, too many files, there is no way, only to find ways, fortunately the name is a regular

For example

yzloan-gdtyyb-v2.23.apk--------->yzloan_relase_gdtyyb.apk

Change to this form

#!/usr/bin/env python
#-*-Coding:utf-8-*-
# @Time: 2016/7/20 11:42
# @Author: Big_bao

Import OS
Import Sys

def Rename (args):
#def Rename (args= '/root/python/python_day_practice/720/tuiguangbao/'):
Files=os.listdir (args)
For File in Files:
L = File.split ('-')
A = l[0]+ ' _relase_ ' +l[1]+ ' apk '
Print (file+ '---+a)
Os.rename (Args+file,args+a)
filename = raw_input ("Please input your filename:")
Rename (filename);

Execute Python file



Reference article:

http://blog.csdn.net/fengyu09/article/details/17843119

Http://jingyan.baidu.com/article/fb48e8be37b6696e622e14db.html

Python Bulk Change file name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.