create needed directories when writing files, deal with empty match sets