Dirculese update: PrefixHandler and SuffixHandler
Late last year, I wrote a desktop file organizer called Dirculese (see this post). At the time, Dirculese had only a single handler, ExtensionHandler
, which would organize files based on their extensions. Over the winter break I added two new handlers, which organize files based on their prefixes and suffixes.
PrefixHandler
PrefixHandler targets any file whose name portion (excluding extension) includes a substring in the PrefixDelimiters
array. Matching files are either deleted (if Delete
is true) or moved into a subdirectory of Target
. Subdirectories are named using the portion of the file's name that precedes the prefix delimiter and are automatically created if they don't already exist.
For example, consider the below file listing:
pre1__test1.txt
pre1__test2.txt
pre1__test3.txt
pre2--test1.txt
pre2--test2.txt
pre2--test3.txt
pre3++test1.txt
And the below rule in the .dirculese.json
file:
"Rules": [
{
"Target": "/path/to/a/target/directory",
"Delete": false,
"Handler": "PrefixHandler",
"Extensions": [],
"PrefixDelimiters": [
"__",
"--"
],
"SuffixDelimiters": [],
"SizeMax": 0,
"SizeMin": 0,
"DateMax": 0,
"DateMin": 0
},{
"Target": "/path/to/a/target/directory",
"Delete": true,
"Handler": "PrefixHandler",
"Extensions": [],
"PrefixDelimiters": [
"++",
],
"SuffixDelimiters": [],
"SizeMax": 0,
"SizeMin": 0,
"DateMax": 0,
"DateMin": 0
}
]
Based on the above configuration, Dirculese would create two new subdirectories in /path/to/a/target/directory
: pre1
and pre2
.
The contents of pre1
would be:
pre1__test1.txt
pre1__test2.txt
pre1__test3.txt
The contents of pre2
would be:
pre2--test1.txt
pre2--test2.txt
pre2--test3.txt
The contents of /path/to/a/target/directory
would be pre1
and pre2
(pre3++test1.txt
would have been deleted due to the second rule in the configuration file).
SuffixHandler
SuffixHandler works exactly like PrefixHandler, except that subdirectories are named using the portion of the file's name that follows the prefix delimiter, and the delimiter substrings are matched against entries in the SuffixDelimiters
array.