title: Need a code to organize files into folders called the file names
body: <p>I'm writing a code to organise a set of files within a folder by creating folders with the original file names in a different folder </p>
  
  <p>I've written the first set of code that organises the files into folders but would like to exclude .Bat files from the code ( so that the batch file itself isn't organised into folders and stays in the %cd%) I also need to adjust the output to a different location</p>
  
  <pre><code>@echo on
  setlocal
  set "basename=."
  for /F "tokens=1* delims=." %%a in ('dir /B /A-D ^| sort /R') do (
  
  set "filename=%%a"
  setlocal EnableDelayedExpansion
  
  
     for /F "delims=" %%c in ("!basename!") do if "!filename:%%c=!" equ "!filename!" (
  
  set "basename=!filename!"
        md "!basename!"
     )
  
     move "!filename!.%%b" "!basename!"
     for /F "delims=" %%c in ("!basename!") do (
  :nextprogram
        endlocal
        set "basename=%%c
     )
  )
  </code></pre>
  
  <p>expected results: run this batch file in a folder with files. All files are put into their individual folders with the file name now the parent folder name. Ignore .bat file and move output to a different location.</p>