wieder ein Problem

mit diesem Script:
Code: Alles auswählen
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import shutil
suchpfad = '/home/thomas/script/pytest'
zielpfad = '/home/thomas/musik'
dateiendung = '.mp3', '.flac', 'wav'
test = []
sauber_liste = []
def verschieben():
print('Kopiere:', os.path.join(os.path.dirname(alt), os.path.basename(alt)))
print('Nach:',neu)
##shutil.copytree(alt, neu)
##shutil.move(alt, neu)
for pfad, verzeichnis, dateien in os.walk(suchpfad, topdown=False):
for d_name in dateien:
d_endung = d_name.endswith(dateiendung)
d_pfad = os.path.join(pfad, d_name)
if d_endung:
musik_verz = os.path.dirname(d_pfad)
test.append(musik_verz)
sauber_liste = sorted(set(test), key = test.index)#wegen doppelter einträge in liste
sauber_liste.remove(suchpfad)#suchpfad aus liste löschen
for alt in sauber_liste:
neu = os.path.join(zielpfad, os.path.basename(alt))
verschieben()
###****LOSE LIEDER****
## if alt == suchpfad:
## for lose_lieder in os.listdir(alt):
## pfad_lose_lieder = os.path.join(alt, lose_lieder)
## if os.path.isfile(pfad_lose_lieder):
## print('Loses Lied:',lose_lieder)
Gruß[Kopiere: /home/thomas/script/pytest/Hannes_Wader_-_7_Lieder
Nach: /home/thomas/musik/Hannes_Wader_-_7_Lieder
Kopiere: /home/thomas/script/pytest/BlackSabbath_Best_off/CD1
Nach: /home/thomas/musik/CD1
Kopiere: /home/thomas/script/pytest/BlackSabbath_Best_off/CD2
Nach: /home/thomas/musik/CD2
/quote]
Nun möchte ich natürlich nicht das /home/thomas/musik/CD2 ausgegeben wird, sondern "/home/thomas/musik/BlackSabbath_Best_off/CD2" und "/home/thomas/musik/BlackSabbath_Best_off/CD1".
Wie (womit) komme ich an "BlackSabbath_Best_off"?
mit os.path.dirname() bekomme ich dies:oder das:os.path.dirname('/home/thomas/script/pytest/BlackSabbath_Best_off')
'/home/thomas/script/pytest'os.path.dirname('/home/thomas/script/pytest/BlackSabbath_Best_off/CD1')
'/home/thomas/script/pytest/BlackSabbath_Best_off'
wattwurm