1

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

The source directory has a structure as follows:

\\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 it to create a folder based on the mkv file name, and then move Movie*.* into that folder so 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
Joey
  • 344,408
  • 85
  • 689
  • 683
Dizzy49
  • 1,360
  • 24
  • 35

1 Answers1

2

Edited to use path specified in comment

@echo off
pushd D:\Video
for %%F in (*.mkv) do (
  2>nul md "%%~nF"
  >nul move /y "%%~nF*.*" "%%~nF"
)
popd
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • 1
    Maybe change the `*.txt` to something appropriate to the question ;) – `*` should probably do the job. – Joey Jul 11 '12 at 21:35
  • @Joey - Oops! Thanks, I'll fix that. – dbenham Jul 11 '12 at 21:43
  • Ok, I changed the "\\Movies" to "D:\Video", copied to a .bat file, and ran it, and it's giving me "The syntax of the command is incorrect." – Dizzy49 Jul 11 '12 at 21:46
  • @Dizzy49 - I can't imagine what is not working. I've tested on Windows 7 and it works fine for me. It also should work on prior Windows versions to at least XP. – dbenham Jul 11 '12 at 21:52
  • I have Windows 7. Am I missing something obvious? I just need to copy/past it into a .bat file, and then run it, correct? I don't need to run it a certain way, using a certain program or anything? – Dizzy49 Jul 11 '12 at 22:01
  • @Dizzy49 - It should be just that simple. I've modified the code to use "D:\Video". Your code should look exactly like above. – dbenham Jul 11 '12 at 22:11
  • Ok, first off, I'm stupid. I thought I turned off another program that polls that folder, so it moved them already (eyeroll). Secondly, it moved everything (movie.mkv, movie.jpg, but it missed movie-fanart.jpg). I changed `>nul move /y "%%~nF.*" "%%~nF"` to `>nul move /y "%%~nF*.*" "%%~nF"` to correct that. Thanks!! – Dizzy49 Jul 11 '12 at 22:21