Have a Exec that likes to download the internet. Free files and such. Of course its all mixed and in a download directory. I know that one of the admins before me had a script written but took it with him.

Can anyone steer me in the right direction on how to sort the files by extension and dump those into certain folders?


If you want a 'pure' batch file solution, copy the following code into a file and run it. It is designed so that the bat file will reside in an upper level directory, but it will process the files in the current directory.

@echo off

for /f "delims=\" %%i in ('dir c:\test\*.* /l /b') do (
echo "%%i"
set str=%%~xi
IF NOT EXIST ".\!str:.=!" mkdir ".\!str:.=!"
copy /y "%%i"  ".\!str:.=!\%%i"
del /f "%%i"

For example to use,

  • put the bat file in c:\
  • open a command prompt
  • cd into c:\files
  • run the bat file.

Let me know if you need any more info.


In vbScript you'll want to look at the FileSystemObject.


You may also want to consider looking at a Powershell Script if that's an option to you. This site will map the FSO methods to new PowerShell Cmd-lets.


  • No problem. Feel free to drop a line if you run into problems. – Jeffery Smith Nov 7 '11 at 21:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.