Improve write method

Upload of directories is now working