#-*- coding:utf-8 -*-

import os,sys,glob,shutil

path
= "D:\\Music"
path_
= "F:\\Music 2012"
temp
= 0
delete
= []
##os.mkdir(path)
def visit(arg,dirlist,filelist):
for filename in filelist:
tem
= os.path.join(dirlist,filename)
delete.append(tem)
if os.path.isfile(tem) and os.path.splitext(tem)[1]=='.mp3':
file_
= open(tem,'r')
file_.seek(
-128,2)
tagdata
= file_.read(128)
file_.close()
if tagdata[:3] == 'TAG':
song_name
= tagdata[3:33].replace('\00','').strip()
singer_name
= tagdata[33:63].replace('\00','').strip()
xx
= song_name+' '+singer_name+'.mp3'
#print xx
#print os.path.split(tem)[
0]
path_xx
= os.path.join(os.path.split(tem)[0],xx)
print path_xx
#if os.path.exists(os)
if xx:
try:
os.rename(tem,path_xx)
global temp
temp
+= 1
t
= os.path.join(path_,singer_name)
if singer_name and (not os.path.exists(t)):
os.mkdir(t)
if not os.path.exists(os.path.join(t,singer_name)):
shutil.copy(path_xx,t)
except:
print
'xxxxxxxxxxxxxxxxxx'



os.path.walk(path,visit,None)
print
'change '+ str(temp)

delete
= delete[::-1]
for x in delete:
if os.path.isfile(x):
os.remove(x)
elif os.path.isdir(x):
os.rmdir(x)
os.rmdir(path)
print
'over'
// 能批量处理 没用argv
// encoding 好像有问题 
// shutil.copy os.path.split os.path.splitext os.path.walk os.walk os.rmdir os.mkdir os.remove
// os.path.isfile os.path.isdir os.path.join os.rename os.path.exists
// glob.glob(*.mp3)

  

 posted on 2011-08-02 16:47  eth0  阅读(184)  评论(0编辑  收藏  举报