title: How to split and copy files from multiple folder in train, test and validation folder
body: <p>I have a dataset that is composed by 130 folders containing 32 photos each. </p>
  
  <p>From each folder, I want to copy randomly that photos (26 for training, 3 for testing and 3 for validation) to the the respective subfolder (001, 002, 003...) in train, validation and test folder.
  So I'll have something like this:</p>
  
  <blockquote>
    <ul>
    <li><p>Train set</p>
    
    <ul>
    <li>001 (folder contain 26 photo)</li>
    <li>002 </li>
    <li>003</li>
    <li>....</li>
    </ul></li>
    <li><p>Validation set</p>
    
    <ul>
    <li>001 (folder contain 3 photos)</li>
    <li>002           </li>
    <li>003           </li>
    <li>....</li>
    </ul></li>
    <li><p>Train set</p>
    
    <ul>
    <li>001 (folder contain 3 photos)</li>
    <li>002           </li>
    <li>003           </li>
    <li>....</li>
    </ul></li>
    </ul>
  </blockquote>
  
  <p>This is the code:</p>
  
  <pre><code>import random
  import shutil
  
  n_photo_train = 26
  n_photo_validation = 3
  n_photo_test = 3
  
  for idx in range(130):
  
      source = '/Users/john/photodb_original/{d:03d}'.format(d=(idx + 1))
      dest_train = '/Users/john/photodb_sets/Train/{d:03d}'.format(d=(idx + 1))
      dest_validation = '/Users/john/photodb_sets/Validation/{d:03d}'.format(d=(idx + 1))
      dest_test = '/Users/john/photodb_sets/Test/{d:03d}'.format(d=(idx + 1))
  
      files = random.choice(os.listdir(source))
      photo_train = files[:n_photo_train]
      photo_test = files[26:29]
      photo_val = files[29:]
  
      shutil.copyfile(os.path.join(source, photo_train), dest_train)
      shutil.copyfile(os.path.join(source, photo_val), dest_validation)
      shutil.copyfile(os.path.join(source, photo_test), dest_test)
  </code></pre>
  
  <p>I get this error: <code>IsADirectoryError: [Errno 21] Is a directory: '/Users/john/photodb_original/001/'</code>.</p>
  
  <p>Did I use wrongly shutil.copyfile? Otherwise is there a way to write the code in a more compact and clear way?</p>