added isDir to check whether a directory exist