Android Delete a Python script for a useless resource file

Source: Internet
Author: User

With the Android project, if you do not delete the useless resources in time to install the package will be more and more large, it is time to tidy up the discarded resources shrink package, young!

In fact, to determine whether a resource (drawable,layout) is not used very simple, the file name (does not include the suffix) to go to the document to look for the line, not found there is no use, directly deleted it can be

Python's string handling is relatively simple, and a script is written for you to refer to:

Import OS
Import Os.path
RootDir = ' D:\HitFm_v2.1.6\hitfm\src '

Pngfiles = []
Xmlfiles = []
Javafiles = []
Tempfiles = []

For Parent,dirnames,filenames in Os.walk (ROOTDIR):
For filename in filenames:
if (Filename.find ('. png ')! =-1):p Ngfiles.append (Os.path.join (parent,filename))
if (Filename.find ('. jpg ')! =-1):p Ngfiles.append (Os.path.join (parent,filename))
if (Filename.find ('. xml ')! =-1): Xmlfiles.append (Os.path.join (parent,filename))
if (Filename.find ('. java ')!! =-1): Javafiles.append (Os.path.join (parent,filename))

For Pngfile in pngfiles:
Pngname = pngfile.split (' \ \ ') [-1]
Pngnowname = Pngname.split ('. ') [0]
if (pngfile.find (' res ') = =-1): Continue
Bfind = False
for javafile in javafiles:
F = open (Javafile, ' RB ') br> javastr = F.read (). Decode ()
if (Javastr.find (pngnowname)! =-1): bfind = True
for xmlfile in xmlfiles:
F = o Pen (xmlfile, ' RB ')
Javastr = F.read (). Decode ()
if (Javastr.find (pngnowname)! =-1): bfind = True
if (bfind = = Fal SE):
print (pngfile)
Os.remove (pngfile)

For xmlfile in Xmlfiles:
XMLName = xmlfile.split (' \ \ ') [-1]
Xmlnowname = Xmlname.split ('. ') [0]
if (Xmlfile.find (' res ') = = =-1): Continue
bfind = False
For Javafile in Javafiles:
f = open (Javafile, ' RB ')
Javastr = F.read (). Decode ()
if (Javastr.find (xmlnowname)! =-1): Bfind = True
For XmlFile2 in Xmlfiles:
f = open (XmlFile2, ' RB ')
Javastr = F.read (). Decode ()
if (Javastr.find (xmlnowname)! =-1): Bfind = True
if (bfind = = False):
Print (xmlfile)
Tempfiles.append (xmlfile)
For Tempfile in Tempfiles:
Print (Tempfile)
Os.remove (Tempfile)

When using only need to change RootDir = ' D:\HitFm_v2.1.6\hitfm\src ' to their own code directory, the command line execution xx.py (need to install python3.0 above version of the interpreter)

Android Delete a Python script for a useless resource file

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