OPT: added check folder existence to differentiate file and folder