Batch sort movies by name into folders

October 24, 2010 at 00:07:28
Specs: Windows 7
I have a rather large movie collection. I am making a batch script to sort my movies.
The way I need them sorted is a folder for each movie, and then those folders in #, A, B, C etc.

So for example F:\Movies\P\Pinocchio\Pinocchio.avi

I have worked out how I can create a folder for each file:

for %%a in (*.avi) do (
md "%%~na" 2>nul
move "%%a" "%%~na"
)

(and do the same for each movie extension that I have (mkv, wma, etc).

Once the files are all in their folders, I can't work out how to sort the folders from the first letter -so all movies starting with A go to /A, all starting with B go to /B and so forth. All movies starting with numbers would go to /#...

I am looking for some help on how to do this.

Thanks
John


See More: Batch sort movies by name into folders

Report •

#1
October 24, 2010 at 03:41:42
Better to do the job just one time and there is no need to sort.
WARNING: batch not tested.

@echo off & setlocal EnableDelayedExpansion
for %%a in (*.avi) do (
  set movie=%%~na
  set movie=!movie:~0,1!\!movie!
  for /L %%b in (0 1 9) do if "!movie:~0,1!"=="%%b" set movie=#!movie:~1!
  if not exist "!movie!" md "!movie!"
  move "%%a" "!movie!"
) 


Report •

#2
October 24, 2010 at 04:27:04
Thanks! That works with plain files, but is there any way that I can get it to simply move the folders too - its just that I currently have some folders already for the movies, so about 5% of my movies are already in folders, but just not in their A B C D folders...

Report •

#3
October 24, 2010 at 10:00:40
Here the ultimate version to move both movie names and folders (tested).
When posting, please always explain the full scenario, not bit per bit.

@echo off & setlocal EnableDelayedExpansion

:: Move movie file names

for %%a in (*.avi) do (
  set movie=%%~na
  set movie=!movie:~0,1!\!movie!
  for /L %%b in (0 1 9) do if "!movie:~0,1!"=="%%b" set movie=#!movie:~1!
  if not exist "!movie!" md "!movie!"
  move "%%a" "!movie!"
) 

:: Move movie folder names

for /D %%a in (*) do (
  set movie=%%~na
  if not "!movie:~1,1!"=="" (
    set movie=!movie:~0,1!
    for /L %%b in (0 1 9) do if "!movie!"=="%%b" set movie=#
    if not exist "!movie!" md "!movie!"
    move "%%a" "!movie!"
  )
)


Report •

Related Solutions

#4
October 24, 2010 at 13:51:44
Thank you very much - worked perfectly!

Report •

Ask Question