import dicom
import os
def eachFile(filepath):
for file in os.listdir(filepath):
child = os.path.join(filepath, file)
if(os.path.isdir(child)):
eachFile(child)
else:
if os.path.splitext(child)[1] == ".dcm":
# print(child)
ds = dicom.read_file(child)
print(ds.UID)