refactoring for funtion copyToDatabaseDirectory