/// <summary> /// Check all given files if they are readable and writable. /// </summary> private Check CheckFilesAccessible(string[] files) { var result = Check.Create(); foreach (var file in files) { try { using (var fileStream = new FileStream(file, FileMode.Open)) { if (false == fileStream.CanRead && fileStream.CanWrite) { TerminalWriter.WriteLocation(); SetResultNotAccessible(result, file); } } } catch (DirectoryNotFoundException) { TerminalWriter.WriteLocation(); result = SetResultNotAccessible(result, file); } catch (Exception) { TerminalWriter.WriteLocation(); result = SetResultNotAccessible(result, file); } } return(result); }
private bool IsWritable(string file) { try { FileStream fs = new FileStream(file, FileMode.OpenOrCreate, FileAccess.ReadWrite); fs.Close(); return(true); } catch (Exception) { TerminalWriter.WriteLocation(); return(false); } }
private Check CheckFilesExist(string[] files) { var result = Check.Create(); foreach (var file in files) { if (false == File.Exists(file)) { TerminalWriter.WriteLocation(); result.CheckResult = CheckResult.Error; result.Messages.Add(new TerminalMessage() { Color = Color.Red, Message = $"{file} is not a file." }); } } return(result); }