Python bulk Modify file format

Source: Internet
Author: User

It is a tedious step to change the format of multiple apk format files into a ZIP package at work. Using a Python script and customizing the right-click Run. py file to bring great convenience to the job, here is a simple introduction:


To modify the APK package name: xxxx_cn.apk;

Modified ZIP package name:;

Before the operation of the batch modified APK file into the same folder, and the following written. py script files are also put in the inside.

Python code:

import os                            #导入os系统命令格式format = ' zip '                           #自定义要修改的文件格式filenames =os.listdir (OS.GETCWD ())    #进入当前目录, and define the files in the current directory as Filenamesfor filename  in filenames:          #对每一个文件进行遍历操作      i=filename.split ('. ')            #用 '. ' As a separator, separate     if filename!= ' change to ' from the file name characters  and i[-1]!= format:       #由于在操作中要把. py file to the file directory you want to modify, so filter the. py file do not do this format operation, with        If the file suffix is. zip also do not modify         t=filename.split ('_')          #再一次对文件进行The key character is ' _ '         os.rename (filename,t[0]+ '. ') +format)    #重命名文件

In this way, all the apk files placed in the target folder will be modified to the ZIP format. In the future if there are new APK package to be modified, do not clean the target file existing Zip package, directly pull the modified file to the target directory to repeat the above operation.

It is important to note, however, that running the. py file is performed in the terminal input Python (the default Linux installation Python plugin). Of course, in a Linux system you can customize the right-click shortcut to run directly. py file, here is not a cumbersome introduction, you can see another blogger on the Linux system to customize the shortcut key article.

Python bulk Modify file format

Related Article

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: 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.