1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| import os,sys
from shutil import copyfile
filelist=[]
pathepub=""
pathfile=[]
pathfileexistant=[]
temp=os.path.realpath(__file__).replace("\\", "/").rsplit("/",1)
argument1= temp[0]
print ("Repertoire en cours : " + argument1)
question = (input ("Est ce le bon repertoire? O ou o puis entrée pour continuer \n"))
if question == "O" or question == "o":
print ("Repertoire défini : " + argument1)
else:
argument1=""
argument1=(input('Tapez le chemin vers les epub ou rien pour sortir : (comme J:\\stock\\ebook )\n')).replace("\\", "/")
if not len(argument1):
sys.exit()
else: print ("Repertoire utilisé : " + argument1)
if os.path.isdir(argument1):
pathepub=argument1.replace("\\", "/")
fileindir = os.listdir(argument1)
for file in fileindir:
if os.path.isfile(pathepub+"/"+file) and ( file.endswith(".epub") or file.endswith(".EPUB") or file.endswith(".pdf") or file.endswith(".PDF")) :
filelist.append(file)
if file.find("-")>0:
tempsplit=file.rsplit("-",1)
if tempsplit[0].find("et"):
temp = tempsplit[0].split("et")
pathfile.append(pathepub + "/" + temp[0])
else:
if tempsplit[0].find("&") :
temp = tempsplit[0].split("&")
pathfile.append(pathepub + "/" + temp[0])
else: pathfile.append(pathepub + "/" + tempsplit[0])
else: pathfile.append(pathepub + "/" + "xxxxx_Sans_tiret_xxxxxx")
if os.path.isdir(pathepub+"/"+file):
pathfileexistant.append(pathepub + "/" + file)
if not len(filelist):
sys.exit()
ligne=0
for epubfile in filelist:
fait=True
if (len (pathfileexistant)):
for pathexistant in pathfileexistant:
if pathexistant.find("[")>0 and fait:
temp = pathexistant.split("[")
if (temp[0] == pathfile[ligne]):
copyfile(pathepub + "/" + epubfile, pathexistant + "/" + epubfile)
ligne+=1
fait=False
if (fait):
os.makedirs(pathfile[ligne], exist_ok=True)
copyfile(pathepub + "/" + epubfile, pathfile[ligne] + "/" + epubfile)
print(epubfile + " copié dans : " + pathfile[ligne] + "/" + epubfile)
ligne+=1
listerep = os.listdir(pathepub)
for rep in listerep:
if os.path.isdir(pathepub+"/"+rep):
listefile = os.listdir(pathepub+"/"+rep)
nbepub = (len (listefile))
if rep.find("[")>0:
temp=rep.split("[")
os.rename(pathepub+"/"+rep, pathepub+"/"+temp[0]+"["+ str(nbepub)+"]")
print ("Répertoire recompté : " + pathepub+"/"+temp[0]+"["+ str(nbepub)+"]")
else :
os.rename(pathepub+"/"+rep, pathepub+"/"+rep+"["+ str(nbepub)+"]")
print ("Répertoire crée: " + pathepub+"/"+rep+"["+ str(nbepub)+"]")
nbepub=0
print ("Nombre de fichier epub copiés : " + str(ligne))
input() |
Partager