Added some guards in file utils.
Fixed a bug in emscripten file utils.
Merge pull request #3227 from azmeuk/file-utils

Added some guards in file utils