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