Directories Template
- See also: Rename, Move, and Copy Files
The Directories Template is used to set the base path and directories used to store your files. You set a Base Path that will be used for all files selected in the tool (this would typically contain the disk letter or volume name), and then a Rule which auto-generates the directories used based on each file's metadata. The Directories Template does not consider the source directories, disk, or volume, and the selected files can come from a variety of source locations.
For example, you might want to consolidate files from a variety of source locations on disk into a common media folder, and then put each file in folders corresponding to their [Artist] property, with sub-folders for each [Album].
Use
The Directories Template consists of two main components:
- Base Path: The portion of the destination path that will be identical for all files selected.
- Rule: The portion of the destination path that will be generated based on the metadata from each file.
Base Path
This is the "root" folder where Media Center will move or copy the files. This path will be identical for all files processed by the template. You can click the Browse button to choose from a disk location using the standard OS directory picker, or you can type a path into the text box. This portion of the path will be used verbatim, and any folders specified that do not exist will be created automatically.
Rule
This is the portion of the destination path that will be generated using the metadata from the files processed by the template. You construct the template's rule using the following system:
- If the Directories Template is not enabled, the files' existing directory paths will be passed through untouched.
- Insert file-specific properties by using the standard Library Field square bracket notation, such as [Artist], [Album], [Series], or [Genre].
- The rule may also contain Expression Language functions.
- All text entered that does not match a valid Library Field or Expression Language function will be passed through verbatim.
- The rule section of the Directories Template also has an option to handle multiple artists. If you'd like all files that have more than one [Artist] value to be placed in a folder named (Multiple Artists) then enable Use '(Multiple Artists)' for [Artist] on multi-artist albums. Otherwise, the first [Artist] in the list will be used.
- The disclosure button in the Rule text box shows a pop-out menu that shows recently-used templates, a few presets, allows you to insert Expression Language functions, and other handy tools.
Preserving Existing Directories
When the Directories Template is enabled, it always processes the entire path of the files starting with the Base Path. If you want to add to, or alter, just one portion of the directory structure then you will need to ensure that the Directories Template you use replicates the current file and folder structure on disk entirely, and add your modification. If the selected files are on a variety of separate volumes, you may need to break up your work into smaller pieces and set the Base Path accordingly for each "round" of changes.
Alternatively, you may want to consider using a different Template instead, such as:
- Find & Replace Template: Which can alter the existing filename by searching for and replacing text.
- Filename Template: Which, in addition to controlling the names of the files, can also be used to add directories to the existing directory structure.
Example
The easiest way to understand how to use the Directories Template system is with examples. Suppose you have a set of music files you'd like to consolidate into the following filesystem location:
- /Users/Shared/Media
Within this location, you'd like a folder structure with folders for the media types, artist, album, and disc number, like this:
To do this, you could use something like this:
- Base Path: /Users/Shared/Media
- Rule: [Media Type]/Music/[Artist]/[Album]/[Disc #]
So, if you'd selected an audio file by Pink Floyd disc 1 of The Wall, you'd end up with this directory path:
/Users/Shared/Media/Audio/Music/Pink Floyd/The Wall/1/
Notice how the "/Music/" term is passed through untouched. Any term included in a Rule that does not match a valid Library Field and which isn't a valid Expression, is passed through verbatim. If the files were all tagged with [Media Sub Type] set to "Music", then you could accomplish the same thing with this rule instead:
[Media Type]/[Media Sub Type]/[Artist]/[Album]/[Disc #]
The examples shown above uses POSIX-style paths from Mac OSX, but the Directories Template works exactly the same way on Windows. The Base Path can start with either a drive letter, or a UNC path for files stored on a network share.
Using Expressions in Templates
The simple example above has a problem, however. When you include the [Disc #] field for files which are tagged with a non-zero value, then it works perfectly. But, if you try to use this rule for files where the [Disc #] value is blank or zero, then you end up with:
The reason for this is explained in the Empty Fields section of the Rename, Move, and Copy Files article.
However, you can easily work around this using a simple expression in your template:
- Rule: [Media Type]\Music\[Artist]\[Album]\if(isempty([Disc #],1),,[Disc #])
This includes the [Disc #] value if it exists, and omits it if it doesn't:
More
- Rename, Move & Copy Files uses "unknown" for blank fields
- A clever eye will notice the [Artist Letters] field in the example screenshot above. Read the same thread to learn how to do that.