Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

closed as off topic by mailq, Ward, Gilles, Iain, gWaldo Nov 8 '11 at 13:06

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 3 down vote accepted

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.

share|improve this answer
Excellent @Sam Thanks! – mikedopp Nov 8 '11 at 15:27

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.

share|improve this answer
Excellent. Thanks for the Direction. – mikedopp Nov 7 '11 at 21:06
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.