Sort file into subfolder (Create folders based on pattern)

At the moment, I've created a rule for every file i've encountered. For example:
name1.info.txt
name2.info.txt
The rule would then look for the specific keyword being "name1" then create a folder called "name1" then move "name1.info.txt" into the newly created folder. Using a brute force method this can be easily achieved for every file I want to have organized in this manner but this is very tedious.
Is there a way for us to create a temporary variable that would store the pattern (if found) to be used under "Sort file into subfolder" to create a directory based off the variable (if found)?
Also if such a solution would be possible, I would also like to run something similar to "sed" against the variable where we can replace characters such as a period with an empty space before using the variable to create the directory.
If this is not possible I guess I could write a bash script to perform all these actions and have hazel execute it. But it would be nice to have this kind of flexibility built into hazel instead.
Thanks!
{EDIT}
Never mind.... I just figured out how to run an embedded shell script. What an amazing app!
For anyone that is interesting here is the code:
name1.info.txt
name2.info.txt
The rule would then look for the specific keyword being "name1" then create a folder called "name1" then move "name1.info.txt" into the newly created folder. Using a brute force method this can be easily achieved for every file I want to have organized in this manner but this is very tedious.
Is there a way for us to create a temporary variable that would store the pattern (if found) to be used under "Sort file into subfolder" to create a directory based off the variable (if found)?
Also if such a solution would be possible, I would also like to run something similar to "sed" against the variable where we can replace characters such as a period with an empty space before using the variable to create the directory.
If this is not possible I guess I could write a bash script to perform all these actions and have hazel execute it. But it would be nice to have this kind of flexibility built into hazel instead.
Thanks!
{EDIT}
Never mind.... I just figured out how to run an embedded shell script. What an amazing app!
For anyone that is interesting here is the code:
- Code: Select all
# Remove path from name.
file=`basename "$1"`
# Strip ".S00E00*.mkv"
name=`echo $file | sed 's/\.[sS][0-9]*[eE][0-9]*.*//g'`
# Strip ".00x00*.mkv"
if [ "$file" = "$name" ]; then
name=`echo $file | sed 's/\.[0-9]*[xX][0-9]*.*//g'`
fi
# Unknown Pattern
if [ "$file" = "$name" ]; then
exit
fi
# Replace periods, underscores with white space.
name=`echo $name | sed 's/[\._]/ /g'`
# Capitilize first character for every word.
folder=`echo $name | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1'`
# Create & Move file to folder.
if [ ! -d "$folder" ]; then
mkdir "$folder"
fi
mv "$file" "$folder"