Need a script to create folders based on file names and automatically move files

I need a batch file (for Windows) that I can run, which will take a (very) large number of files and put them in their own folders.

The source directory has the following structure:

\\Movies\Movie1.mkv \\Movies\Movie1.idx \\Movies\Movie1.sub \\Movies\Movie1.jpg \\Movies\Movie1.mkv_sheet.jpg \\Movies\Movie2.mkv \\Movies\Movie2.idx \\Movies\Movie2.sub \\Movies\Movie3.mkv \\Movies\Movie3.idx \\Movies\Movie3.sub 

I need to create a folder based on the mkv file name, and then move Movie *. * in this folder so that it looks like this:

 \\Movies\Movie1\Movie1.mkv \\Movies\Movie1\Movie1.idx \\Movies\Movie1\Movie1.sub \\Movies\Movie1\Movie1.jpg \\Movies\Movie1\Movie1.mkv_sheet.jpg \\Movies\Movie2\Movie2.mkv \\Movies\Movie2\Movie2.idx \\Movies\Movie2\Movie2.sub 
+1
loops batch-file
source share
1 answer

Edited using the path specified in the comment

 @echo off pushd D:\Video for %%F in (*.mkv) do ( 2>nul md "%%~nF" >nul move /y "%%~nF*.*" "%%~nF" ) popd 
+2
source share

All Articles