Implemented check for directories when inserting files, and files when inserting directories.