Useful Batch Script - Create Directories and move files

Thought I would share this Windows batch script in case someone might find it useful.

What it does is reads all the file names in a directory, creates new directory’s with those file names and then moves the files into the corresponding directory.

I used it for a folder of numbered images. Just double-click the batch script.

FileToFolder.bat

@echo off
for /f "delims=" %%a in ('dir /b') do (
if not "%%~fa"=="%~f0" (
md "%%~na" 2>nul
if exist "%%a" move "%%~na.*" "%%~na"
)
)
1 Like

Thanks. Maybe someone can benefit from this.