public static FileIOResult EnsureDirectory(string directoryPath) { var r = new FileIOResult(); if (!Directory.Exists(directoryPath)) { try { Directory.CreateDirectory(directoryPath); } catch (Exception ex) { r.ErrorMessage = ex.Message; } } return(r); }
public static FileIOResult EnsureFile(string file) { var r = new FileIOResult(); var fi = new FileInfo(file); var dr = EnsureDirectory(fi.DirectoryName); if (!dr.Success) { r.ErrorMessage = dr.ErrorMessage; return(r); } if (!File.Exists(file)) { try { File.Create(file); } catch (Exception ex) { r.ErrorMessage = ex.Message; } } return(r); }