Page 1 of 1

Reorganizing by year, maintaining subfolder structure?

PostPosted: Sun Mar 08, 2015 10:20 pm
by felciano
Hi --

I'm trying to get hazel to help me partition a large collection of date-stamped PDF financial statements by year and by account. They are currently organized by account, which is useful, but each account has accumulated many years worth of statements, so I'd like to restructure so all information for a given year is stored together, still organized by account.

For example, my current structure looks something like this (assuming 3 accounts):

Code: Select all
Original/
    MyBank ABC/
        2014-11-01 mybank ABC statement.pdf
        2014-12-01 mybank ABC statement.pdf
        2015-01-01 mybank ABC statement.pdf
    MyBank DEF/
        2014-11-01 mybank DEF statement.pdf
        2014-12-01 mybank DEF statement.pdf
        2015-01-01 mybank DEF statement.pdf
    MyUtilities XYZ/
        2014-11-01 gas XYZ statement.pdf
        2014-12-01 gas XYZ statement.pdf
        2015-01-01 gas XYZ statement.pdf


What I'd like it to look like:

Code: Select all
New/
    2014/
        MyBank ABC/
            2014-11-01 mybank ABC statement.pdf
            2014-12-01 mybank ABC statement.pdf
        MyBank DEF/
            2014-11-01 mybank DEF statement.pdf
            2014-12-01 mybank DEF statement.pdf
        MyUtilities XYZ/
            2014-11-01 gas XYZ statement.pdf
            2014-12-01 gas XYZ statement.pdf
    2015/
        MyBank ABC/
            2015-01-01 mybank ABC statement.pdf
        MyBank DEF/
            2015-01-01 mybank DEF statement.pdf
        MyUtilities XYZ/
            2015-01-01 gas XYZ statement.pdf


The key thing is that I am not under control of the subfolder names, and new ones get created periodically as new accounts are created. So I'm looking for a solution general enough that if e.g. "MyNewBank LMN" shows up it will be handled as well. Is that doable with Hazel?

Thanks!

Ramon

Re: Reorganizing by year, maintaining subfolder structure?

PostPosted: Mon Mar 09, 2015 12:02 pm
by Mr_Noodle
Look up "match patterns" in the help. You can grab the year and everything after the date into custom attributes and then rearrange things based on that.

Re: Reorganizing by year, maintaining subfolder structure?

PostPosted: Mon Mar 09, 2015 11:51 pm
by felciano
My apologies @Mr_Noodle, my original post was too broad and neglected to highlight the specific problem I'm struggling with.

I am familiar with the match patterns have matched PDF filenames including separating out variables for date, account number and organization. I've also played with the sort into subfolders actions that have let me successfully sort the PDF files into folders by year.

What I can't figure out how to do is how to have this "sort into subfolders [by year]" action move the parent folders as well, creating copies for each year if necessary. Unlike the copy command, I haven't found a "copy folder structure" option (like in the Copy command).

The subtlety here is that the parent folders (e.g. "MyBank ABC/" in my example) are not always named the same as, or a substring of, the filenames of the enclosed PDFs.

Any suggestions on strategies to copy both this directory structure, with its potentially distinct naming conventions, as well as the enclosed files? Is there a way to do this in a single pass, or do I need to perhaps first try to clone the directory structure(s) in one fell swoop, then handle the files?

Thanks again for your help,

Ramon

Re: Reorganizing by year, maintaining subfolder structure?

PostPosted: Tue Mar 10, 2015 12:21 pm
by Mr_Noodle
You can try instead having the rule match the parent folders. You can create a nested condition (hold down option while clicking the + button to create new conditions) and try and match according to the folder's contents but I'm not sure if even this will work if the contents need to go to different places. I think you might need to write a script to do something along these lines.

Or, you can try matching against the files, but also doing a nested condition to match against the enclosing folder (or maybe two nested conditions to get the folder two levels up). Have something like "Name matches (*parent name)" which will capture the name of that parent folder and then you can use that in the Sort into subfolder pattern.

Re: Reorganizing by year, maintaining subfolder structure?

PostPosted: Tue Mar 10, 2015 1:27 pm
by felciano
Thanks @Mr_Noodle -- very nice. I didn't know about the ability to have a name match against the parent's name. I'll give that a shot!

Ramon

Re: Reorganizing by year, maintaining subfolder structure?

PostPosted: Tue Mar 10, 2015 11:18 pm
by felciano
Seems to be working well -- thanks again @Mr_Noodle!