Clearing orphaned music files after iTunes library migration
Before transfering the music back as is mentioned in the knowledgebase document, be sure to disconnect the iPod and clear your iTunes library by selecting all files that were synchronized and delete them. When prompted, select the option to move the deleted file to the trash. After this is done, go to the iTunes Media (or iTunes Music) folder and remove all the album and artist folders still present. At this point these should just contain the duplicate files and others that were not in your iTunes library.Using Automator and Finder Search capabilitiesApple's "Automator" can be used to locate and target all the files not included in the iTunes library so you can delete them. Unfortunately this is not as straightforward as it could be because like to the Finder, Automator does not have the ability to find or filter items in the Finder by exclusion (i.e., including all except a specific search criteria). If Apple had this filtering option available, finding the unused duplicate files in the Finder would have been as easy as searching for items that do not include "1.mp3," but this is not an option.Despite these limitations, you can get around them by using the Finder's labels for files and folders. The idea is to set up Automator (or the Finder) to first search for all files that do include "1.mp3" in their names (those that the iTunes Library is using), and then label all the found items with a unique color in the Finder. Once this is done it will be easy to do a Finder search on the folder for files that are not labeled, and be able to remove them in batches.To do this, create a new workflow and then put the following workflow actions in this order:Use this workflow to label the duplicated files that are currently being used by iTunes (click for larger view).Get Specified Finder ItemsBe sure to add the iTunes Music folder (or the "Music" folder within the iTunes Media folder) to the list. You can also use the "Ask for Finder Items" workflow action, but it requires you to select the iTunes Media/Music folder each time the workflow is run. The goal here is to somehow target the parent folder that contains the folders for your artists and albums.Get Folder ContentsBe sure to check the option to "Repeat for each subfolder found"Label Finder ItemsAdd this workflow and click the little "x" to ensure all found items are stripped of their labels before the workflow moves on.Filter Finder ItemsIn the first one of these filtering workflow actions, change it so the kind of file is "Music". This will ensure only music files are passed to the second "Filter Finder Items" action, and allowing the "Any" condition in the next step to work on this subset of files instead of all the ones in the targeted directory.Filter Finder Items (again)This is the key action to modify. With the criteria set so "Any" of the conditions should be met, add as many options to filter by name as you would like to include different file types in your library. Keep in mind that adding more items here will include more files in the search results; however, you can always narrow the resulting list by adding an additional "Filter Finder Items" workflow action after this one. Having multiple filters allows for you fine-tune the search parameters.Choose from ListAdd this workflow action in here as a precautionary step, which will list all the files being targeted so far. At this point you can choose to exclude any files you want to keep by unchecking the corresponding box.Label Finder ItemsSelect any color to use, but keep in mind this whole procedure assumes the files you wish to delete will not be included by the search filters in the 5th an 6th actions in this workflow, and therefore will no be labeled by this step.When run, this workflow will go through the music in your folder, and label all that you want to keep (based on the filter criteria you set up) with the selected label color. Keep in mind you can do something similar by using a Finder search like the procedure described below, so that is an option as well. The goal is to somehow target the duplicated files (that are being used by iTunes) that all share a similar naming pattern, and give them the same label so you can use the label to exclude these files later on.A Finder search of the folder (in this case it's my "iTunes Music" folder) for music files with no label should show the remaining files that are unused by iTunes (click for larger view).Once the files have been labeled, you can easily find the remaining ones by using a Finder search to target the files without any labels. To do this, go to the same iTunes Music folder you targeted with the workflow, and press Command-F to bring up the Find window. From here modify the search parameters right under the window's toolbar so the computer searches within "iTunes Music" (or the "Music" folder within the "iTunes Media" directory, if you have your music organized that way), and then be sure to search by File Name instead of Contents.Now modify the filters so the search includes only music files with no file label. To do this, next to the filter menu entitled "Kind" change "Any" to "Music," and then add a new search filter by clicking the plus button to the right side of the current search filter. In the new search filter, choose "Other" from the first menu, and locate the filter called "File label" (you may need to use the list's search box to find it). Select it, click OK, and then be sure to click the "x" in the label options for this filter so the search only includes items with no label.With these search parameters set up, you should be able to see all the duplicate songs in the search results, and be able to move them or delete them as you see necessary.Questions? Comments? Have a fix? Post them below or email us!Be sure to check us out on Twitter and the CNET Mac forums.