{"id":49,"date":"2009-08-23T21:09:00","date_gmt":"2009-08-23T21:09:00","guid":{"rendered":"http:\/\/www.roysac.com\/blog\/wp-admin\/2009\/08\/sorting-away-mp3-files-into-sub-directories-by-artist-name\/"},"modified":"2009-08-23T21:09:00","modified_gmt":"2009-08-23T21:09:00","slug":"sorting-away-mp3-files-into-sub-directories-by-artist-name","status":"publish","type":"post","link":"http:\/\/www.roysac.com\/blog\/2009\/08\/sorting-away-mp3-files-into-sub-directories-by-artist-name\/","title":{"rendered":"Sorting Away MP3 Files into Sub Directories by Artist Name"},"content":{"rendered":"<p>I just <a href=\"http:\/\/www.roysac.com\/blog\/2009\/08\/processing-files-housekeeping-sorting-and-renaming\/\">published the post<\/a> where I introduced the great and useful tool <a href=\"http:\/\/www.bulkrenameutility.co.uk\/\" target=\"_blank\">Bulk Rename Utility<\/a>. <\/p>\n<p>I first wanted to include the content of this post into that one as well, but then decided to make it a separate post instead. The introductory post of BRU was already getting long enough, especially because I included suggestions and comments to the tool itself, which I originally intended to post at the tool authors support forums. But I wasn&#8217;t able to do that yet, so the post got pretty long and adding something else would just have been too much.<\/p>\n<p>I had a bunch of MP3 files dumped into a folder, several hundred of them. Songs by various artists. They came from some of my old MP3 CD-ROMs that I burned, when I didn&#8217;t have that many CDs (compared to today) and keeping things organized wasn&#8217;t much of a concern for me.<\/p>\n<p>Well, the amount of CDs grew significantly over the years, so sorting and grouping stuff became necessary to be able to find stuff. Also, the number of different music styles that I learned to enjoy increased. Mixing some of those styles is probably not such a great idea.<\/p>\n<h3>The Task at Hand<\/h3>\n<p>Anyhow, the file names followed at least some logic. They usually started with the name of the artist followed by the title of the song, separated by a hyphen or dash (-) character. Some also included the album name or release year after the song title, in parentheses or without, spaces between names and the dash separator or without, using underscores &#8220;_&#8221; instead of spaces or spaces etc.?? <\/p>\n<p>There were usually more than one songs per artists, sometimes only 2 or 3 (singles) and sometimes entire albums. I wanted to create folders for each artist and move each MP3 file into the corresponding directory; a problem that I could not solve with the <a href=\"http:\/\/www.roysac.com\/blog\/2009\/08\/processing-files-housekeeping-sorting-and-renaming\/\">Bulk Rename Utility<\/a> yet (even though it has the option to extract ID3 meta data from MP3s and then do something with it, which I have not figured out yet).<\/p>\n<p>I did not want to do it by hand, because I still have some old CDs with MP3 files flying around where I would have to repeat this task again. So I ended up writing a little DOS BATCH Script to do the work for me.<\/p>\n<h3>MP3 Cleanup\/Sorting Batch Script<\/h3>\n<p>The code for this script can be found below. You can also download the code via the link below. The ZIP archive contains next to the .BAT script file also a neat little intro to promote my web site RoySAC.com hehe.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.roysac.com\/images\/icon\/zip.gif\"><a href=\"http:\/\/www.roysac.com\/files\/RoySAC-SortMP3FileBatchScript.zip\" target=\"_blank\">RoySAC-SortMP3FileBatchScript.zip<\/a><\/p>\n<p>The batch script performs the following set of tasks:<\/p>\n<ol>\n<li>look for MP3 files in the current directory and process each one of them <\/li>\n<li>look for &#8220;-&#8221; in the file name (assumed to be the separator between artist name and song title)  <\/li>\n<li>parse the file name and extract the string before the first &#8220;-&#8220;, also trim trailing spaces  <\/li>\n<li>checks if directory with that name exists\n<ol>\n<li>If not, create the directory (with the artist name) <\/li>\n<\/ol>\n<\/li>\n<li>move the current file into that directory<\/li>\n<\/ol>\n<p>The source code of <strong>MP3FileSort2Dirs.bat<\/strong><\/p>\n<div>\n<pre><span>   1:  <\/span>@echo off<\/pre>\n<pre><span>   2:  <\/span>:: -------------------------------------------------------<\/pre>\n<pre><span>   3:  <\/span>:: MP3 Cleanup\/Sorting Batch Script<\/pre>\n<pre><span>   4:  <\/span>:: ------------------------------------------------------- <\/pre>\n<pre><span>   5:  <\/span>:: 1. looks <span>for<\/span> MP3 files <span>in<\/span> current directory<\/pre>\n<pre><span>   6:  <\/span>:: 2. looks <span>for<\/span> <span>\"-\"<\/span> <span>in<\/span> file name (assumed to be <\/pre>\n<pre><span>   7:  <\/span>::    the separator between Artist Name and Song Title)<\/pre>\n<pre><span>   8:  <\/span>:: 3. parses <span>string<\/span> before first <span>\"-\"<\/span>, trims trailing spaces<\/pre>\n<pre><span>   9:  <\/span>:: 4. checks <span>if<\/span> directory with that name exists<\/pre>\n<pre><span>  10:  <\/span>::   4.1 If not, it creates it (artist name)<\/pre>\n<pre><span>  11:  <\/span>:: 5. moves file into the directory<\/pre>\n<pre><span>  12:  <\/span>:: <\/pre>\n<pre><span>  13:  <\/span>:: Batch Script by Carsten Cumbrowski aka Roy\/SAC<\/pre>\n<pre><span>  14:  <\/span>:: visit http:<span>\/\/www.roysac.com<\/span><\/pre>\n<pre><span>  15:  <\/span>??<\/pre>\n<pre><span>  16:  <\/span>setlocal enabledelayedexpansion<\/pre>\n<pre><span>  17:  <\/span>cls<\/pre>\n<pre><span>  18:  <\/span>::only list files with extension MP3, exclude directories<\/pre>\n<pre><span>  19:  <\/span><span>for<\/span> \/f <span>\"tokens=*\"<\/span> %%A <span>in<\/span> (<span>'DIR \/A-D \/ON \/B \"*.MP3\"^|SORT \/REVERSE'<\/span>) <span>do<\/span> (<\/pre>\n<pre><span>  20:  <\/span>  call :PERFACTION <span>\"%%~A%\"<\/span><\/pre>\n<pre><span>  21:  <\/span>)<\/pre>\n<pre><span>  22:  <\/span>echo.<\/pre>\n<pre><span>  23:  <\/span>echo Done!<\/pre>\n<pre><span>  24:  <\/span>echo.<\/pre>\n<pre><span>  25:  <\/span>pause<\/pre>\n<pre><span>  26:  <\/span><span>goto<\/span> :EOF<\/pre>\n<pre><span>  27:  <\/span>??<\/pre>\n<pre><span>  28:  <\/span>:PERFACTION<\/pre>\n<pre><span>  29:  <\/span>::look <span>for<\/span> dash <span>in<\/span> file name, parse str before dash<\/pre>\n<pre><span>  30:  <\/span><span>for<\/span> \/F <span>\"tokens=1 delims=-\"<\/span> %%B <span>in<\/span> (<span>\"%~1\"<\/span>) <span>do<\/span> (<\/pre>\n<pre><span>  31:  <\/span>::trim trailing spaces from parsed <span>string<\/span>  <\/pre>\n<pre><span>  32:  <\/span>    set str=%%~B%<\/pre>\n<pre><span>  33:  <\/span>    <span>for<\/span> \/l %%a <span>in<\/span> (1,1,31) <span>do<\/span> <span>if<\/span> <span>\"!str:~-1!\"<\/span>==<span>\" \"<\/span> set str=!str:~0,-1!<\/pre>\n<pre><span>  34:  <\/span>)<\/pre>\n<pre><span>  35:  <\/span>call :PROCFILE <span>\"%str%\"<\/span><\/pre>\n<pre><span>  36:  <\/span><span>goto<\/span> :EOF<\/pre>\n<pre><span>  37:  <\/span>??<\/pre>\n<pre><span>  38:  <\/span>:PROCFILE<\/pre>\n<pre><span>  39:  <\/span>::check of directory exists and move file<\/pre>\n<pre><span>  40:  <\/span>set f2=<span>\"%~1\"<\/span><\/pre>\n<pre><span>  41:  <\/span><span>if<\/span> {%~x1}=={} (<\/pre>\n<pre><span>  42:  <\/span>   echo %f2%<\/pre>\n<pre><span>  43:  <\/span>   <span>if<\/span> NOT exist %f2%  MD %f2%<\/pre>\n<pre><span>  44:  <\/span>   move <span>\"%~1*.MP3\"<\/span> %f2%<\/pre>\n<pre><span>  45:  <\/span>)<\/pre>\n<pre><span>  46:  <\/span><span>goto<\/span> :EOF<\/pre>\n<pre><span>  47:  <\/span>??<\/pre>\n<\/div>\n<p><\/p>\n<p>I hope you found this post and script useful. Let me know via the comments section of this blog post below.<\/p>\n<p><\/p>\n<p>Thanks and Cheers!<\/p>\n<p><\/p>\n<p>Carsten aka Roy\/SAC<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just published the post where I introduced the great and useful tool Bulk Rename Utility. I first wanted to include the content of this post into that one as well, but then decided to make it a separate post instead. The introductory post of BRU was already getting long enough, especially because I included [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-tools"],"_links":{"self":[{"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":0,"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}