import os
import shutil
path1 = r"C:\Users\tangx\Desktop\6"
path2 = r"C:\Users\tangx\Desktop\12"
f1 = os.listdir(path1)
f2 = os.listdir(path2)
for i in f1:
if i not in f2:
shutil.rmtree(os.path.join(path1,i))
for j in f2:
if j not in f1:
shutil.rmtree(os.path.join(path2, j))