added support for a third parameter

Output directory and the creation of the directory if it does not exists