Simplified ensureFolderExists function according to Iulian's suggestion.