import re,string,os.path FILE="/home/tux/zixia/test/all.lftp" #FILE="/tmp/1" DEST="/home/mouse/music" URL="http://166.111.158.99/music/" pa=re.compile('[m,M][p,P]3$') fd=open(FILE,'r') line=fd.readline() while line!='': dir,file=os.path.split(line) # newdir=os.path.join(DEST,dir) # newdir is for making new dir in ur DEST newdir=os.path.normpath(newdir) dir=os.path.normpath(dir) if not os.path.exists(newdir): # mkdir #print newdir os.mkdir(newdir) if len(file)!=0 and pa.search(file)!=None: #print 'file is ',file m3u=string.join([URL,dir,'/',file],'') m3u=string.replace(m3u,' ','%20') dirlist=string.splitfields(dir,'/') while len(dirlist)!=0: #remove the last dir recusively #print dirlist new2dir=string.join(dirlist,'/') m3ufile=os.path.join(DEST,new2dir,'play.m3u') fd2=open(m3ufile,'a+') fd2.writelines(m3u) fd2.close() dirlist.pop() line=fd.readline()