title: Iterate DICOM files
body: <p>Im using pydicom to read dicom files (the patient name), but all my dicom files are name as i34, i67 and so on (no specific order or sequence for these names).
  My problem: i have a list of patients names in a txt file and i want search every patient name in this txt file with all the dicom files, looking to their PatientName in the dicom file (for those who are not familiar, every dicom file has a number of informations of a patient, one of them being the PatientName)</p>
  
  <p>Exemple:</p>
  
  <p>txt file:
  John
  George
  Ringo
  Paul</p>
  
  <p>Dicom files:
  i54
  i98
  i64
  i12</p>
  
  <p>What I want:
  Take John and search i54, i98, i64, i12 for the PatientName match. And do it for every name in the txt file. Hope I made my self clear. Thks in advance!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>i try this code but didnt work</p>
  
  <pre><code>import dicom
  import os
  
  dir = "/path/to/dir_where_dicom_file_are"
  txt = open('/path/to/txt_with_patientsnames.txt','r')
  for line in txt:
      for sub, dirs, files in os.walk(dir):
          names = line.strip()
          for dcm in files:
             ds = dicom.read_file(dir+dcm) #necessary for read dicom files                            
             patient = ds.PatientName
             if names in patient:
             #do something
  </code></pre>
  
  <p>I took a sample of 20 dicom images and a sample of 20 names. I knew that only one dicom file of this sample belong to one patient name so my ouput should be only one match righ? but im getting 20 match results out of this. Whats wrong?</p>