Bugfix: create directory before creating files
Bugfix: proper handle regexp match