Share a practical Python script (file classification of different music formats)

Source: Internet
Author: User

Because I personally prefer to listen to music in the APE format, sometimes some songs cannot be found on the Internet for the time being, only the MP3 format will be available first, when the APE format appears on the internet, replace the MP3 music. After a long time, the directory contains both music files in APE format and music files in MP3 format. If you want to know how many MP3 files in the directory can only be sorted by file type in the resource manager, inconvenient. I want to list the number of MP3 files in the directory directly in one file, so that I can download all the files in APE format. Therefore, you can use pythonto write a script. This script is used to write all the file names in the MP3 format under the directory to the mp3list.txt file and collect statistics on the total number of files.

#! /Usr/bin/Python #-*-coding = UTF-8 -*- ''  'All the MP3 files under the directory, and write the file name to the mp3list.txt file'  '' Import osfrom platform import systemdef getmp3filelist (PATH ): ''  'Retrieve the list of all MP3 file names in the directory'  '' Filetype = "MP3" Mp3file = "" Mp3filelist = [mp3file For Mp3fileIn OS. listdir (PATH )\ If Len (mp3file. Split ( "." ) = 2 and mp3file. Split ( "." ) [1] = filetype] Return Mp3filelistdef writemp3filelist (mp3filelist, filename = "Mp3list.txt" ): ''  'Write the file list to a text file'  '' With open (filename, "W" ) As W_file: w_file.write ( "Total: % S % s" % (LEN (mp3filelist), OS. linesep )) For Mp3file In Mp3filelist: w_file.write ( "% S % s" % (Mp3file, OS. linesep )) Return Nonepath = OS. getcwd () # Path = "E: \ music \ Chinese classical" Writemp3filelist (getmp3filelist (PATH ))

Run the script and open mp3list.txt to view the result.

Total

download Source Code

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.