title: Move files based on partial name - DOS/Batch
body: <p>I have this code</p>
  
  <pre><code>pushd "C:\Folders\"
  for %%j in (*) do (
  md "%%~nj"
  move "%%j" "%%~nj"
  )
  popd
  pause
  exit
  </code></pre>
  
  <p>This move files with the same name into a folder with the same name, if the folder does not exist it will create a new folder. Ok great. </p>
  
  <p>This issue I have is that I want the same function as above however I only was it to look at the first 4 characters. E.g.</p>
  
  <pre><code>1234 - sample.jpg
  1234 - sample-sm.jpg
  1234 - sample-new.jpg
  1234 - sample-right.jpg
  
  1235 - sample.jpg
  </code></pre>
  
  <p>1234 files will be moved to the same folder as the first 4 characters are the same, however 1235 will be moved to a new folder because the fist for characters are different. </p>
  
  <p>Thank you</p>
  
  <hr>
  
  <pre><code>@echo off 
  setlocal enabledelayedexpansion
  pushd "C:\Folders\"
  for %%a in (*) do (
    set fldr=%%~na
    set fldr=!fldr:~0,4!
    md "!fldr!"
    move "%%a" "!fldr!"
  )
  popd
  pause
  exit
  </code></pre>
  
  <p>However it creates new folders with the first 4 letters and moves the files to these created folders... It does move everything with the same first 4 letters to the correct folder.</p>
  
  <p>So no I need it NO to make a directory but to move it to the already create directory. </p>