晚上打算把播放器下载下来的音乐拷贝到mp3里边,但是它是如下形式存放的,相当头痛……

Python3整理文件

作为程序员,想到使用python来遍历这个目录,并将有大于限制的音乐文件拷贝到指定目录,相关实现代码如下:

# author:liaoyu
# date  :2014-05-30

import os
import re
import shutil

#音乐目录
dirPath = r'C:\CloudMusic'
#音乐存放目录
distPath = r'D:\pyzone\红心音乐'
if os.path.isdir(distPath) is False:
    os.mkdir(distPath)
for parent,dirnames,filename in os.walk(dirPath):
    for name in filename:
        tempPath = os.path.join(parent,name)
        #根据正则表达式判断文件是否以.mp3结尾
        if re.search( ".+\.mp3",name ) is None:
            continue 
        #只拷贝音乐文件大于2M的
        if os.path.isfile(tempPath) and os.path.getsize(tempPath)/(1024*1024)>2:
            shutil.copy(tempPath,distPath)

 

 

转载于:https://www.cnblogs.com/liaoyu/p/python-move-music.html

相关文章:

  • 2021-12-25
  • 2021-10-16
  • 2021-09-12
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2022-01-30
猜你喜欢
  • 2022-03-03
  • 2022-02-22
  • 2022-12-23
  • 2021-11-28
  • 2021-07-26
  • 2022-01-09
相关资源
相似解决方案