You can grab the script “musicToFolders.sh” from here (a .zip file) or copy it from below. In either case, save the script as “musicToFolders.sh” to the directory where you are putting the files created by XLD—possibly,your Music directory (“~/Music” in the language of the OS X ‘shell’).
Open up your ‘Terminal.app’ (in the ~/Applications/Utilities folder) and navigate to the same directory e.g. by typing “cd ~/Music” if that’s where XLD is putting the files and where you’ve saved “musicToFolders.sh”. Hint: if you type just “cd ” (“cd” + a space) in the terminal and then drag the icon of the folder where XLD has put the files out of the Finder window into the Terminal window, you’ll find the right location is set-out for you; just hit the Enter key.
Now you’ve navigated to the right directory in the terminal, type “chmod +x musicToFolders.sh” and Enter. This sets up the file permissions so you can execute the shell script (you need to do this only once).
In the terminal, type “sh musicToFolders.sh” and hit the Enter key. In a moment you should find that all your music files have been tidied away in folders named more or less the same as your CD. The folder names are taken from XLD’s log files, which rely in turn on the CDDatabase (e.g. FreeDB). They sometimes err on the side of brevity; you may wish to edit the folder names a little to clarify the contents of the folder.
#!/bin/bash # # musicToFolders.sh # A bash shell script from http://www.petergallagher.com.au # This work is in the public domain # Creative Commons CC0 1.0 Universal # # Creates a sub-directory named for each XLD log file # found in the current directory # Puts the log file in the sub-directory # Creates a list of files (filelist.txt) from # the log, each with spaces escaped for f in *.log; do # dont continue if there are no .log files if [ "$f" != "*.log" ]; then mkdir "$"; mv "$f" "$"; # output lines in the log file that contain 'Filename : ' grep -h "Filename : " "$"/"$f" | # grab just the path name sed 's/ Filename : (.*)/1/' | # escape spaces in the path name # and output the line to a file list sed 's/ / /g'> "$"/filelist.txt; else echo "Oops! -- No XLD log files to process in this directory!" fi done # Find the path name of files contained # in list files in all sub-directories # Move the files in the list to the same # subdirectory as the list # process every filelist in sub-directories currDir=$PWD # enclose the dir var in quotes in case of spaces # read the result of find one-line-at-a-time find "$currDir" -name "filelist.txt" -print | while read -e f; do # Read the contents of the filelist.txt into # a new file variable and move the file # to the directory of filelist.txt cat "$f" | while read -e nf; do # Dont try to move files that dont exist if [ -f "$nf" ]; then mv "$nf" "$" fi done; # rename this filelist.txt when we're done mv "$f" "$f".proc; done