moved check for folders and creation of non-existing folders to a separate for-loop ensuring that the folder tree is in place before starting to transfer content.