|
Answer» I have a script currently to sort all my music into Alphabetic Folders (A,B,C, ect) Most of my music is already in folders by artists name (//Queen/Bohemian Rhapsody. - Queen.mp3) However I have some unsorted mp3s in the with the same title format (Song - Artist) that I would like to put into directories by the artists' name. I cannot solve this for the life of me. I can put them into directories with the last letters of the file name but the length VARIES so I might get directories named "sody - Queen" instead of just "Queen" I'm pretty novice user of batch files but I'm trying to get better I just got caught up on this problem which I hope there is a solution to.
Code: [Select]for %%FI in (*.mp3) do ( set file=%%~nFI set folder=!file:~-8! if not exist !folder! md !folder! move "%%~J" "!folder!" ) I got this PIECE of code from this website of someone with a different problem and it works well but like I said the Artist's name will vary so it doesn't work like I need it to.This expects a format of "song - artist.mp3" and it creates a bat file for you to examine and edit if necessary.
Open file.bat in notepad to check it before using it.
If the song name contains a - character then it will need editing. If there are two or more spaces before the artist name then it will need editing.
Code: [Select]@echo off for %%a in (*.mp3) do for /f "tokens=1* delims=-" %%b in ("%%a") do CALL :next "%%a" "%%~nc" goto :EOF :next set "folder=%~2" if "%folder:~0,1%"==" " set "folder=%folder:~1%" >>file.bat echo md "%folder%" 2^>nul ^& move "%~1" "%folder%" goto :EOF Wow thank you works like a charm. Especially because all my files are always song - artist.
Edit: When I put it in with the REST of my code it only works for the first file and that's it. The other file(s) are unaltered. I assume I could run it as a separate file but it would be MUCH better if I could run it in my main batch file.
Edit 2: I'm assuming this has a loop that's not able to loop when its part of a bigger file because instead of "goto EOF" I had it exit and it only created the one folder standalone.Quote from: NehpetsDoom on May 27, 2013, 11:11:23 PM Edit: When I put it in with the rest of my code it only works for the first file and that's it. The other file(s) are unaltered. I assume I could run it as a separate file but it would be much better if I could run it in my main batch file.
It calls a subroutine. If you show us your main batch file then it should be able to be added.
|