title: Create folders based on file names and copy files to them in python
body: <p>I have many files in this folder structure:</p>
  
  <pre><code>test[dir]
    -test1 - 123.avi
    -video[dir]
       -test2 - 123.avi
  </code></pre>
  
  <p>I want to create folders based based on file names (e.g. test1, test2) in the target dir and move files to respective folders.</p>
  
  <p>I tried this based on code from another thread:</p>
  
  <pre><code>#!/usr/bin/env python
  
  import os, shutil
  
  src = "/home/koogee/Code/test"
  dest = "/home/koogee/Downloads"
  
  for dirpath, dirs, files in os.walk(src):
      for file in files:
          if not file.endswith('.part'):
              Dir = file.split("-")[0]
              newDir = os.path.join(dest, Dir)
              if (not os.path.exists(newDir)):
                  os.mkdir(newDir)
  
              shutil.move(file, newDir)
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 8, in &lt;module&gt;
    File "/usr/lib/python2.7/shutil.py", line 299, in move
      copy2(src, real_dst)
    File "/usr/lib/python2.7/shutil.py", line 128, in copy2
      copyfile(src, dst)
    File "/usr/lib/python2.7/shutil.py", line 82, in copyfile
      with open(src, 'rb') as fsrc:
  IOError: [Errno 2] No such file or directory: 'test1'
  </code></pre>
  
  <p>What is weird is that there is a folder created in /home/koogee/Downloads named 'test1'</p>