How to check if a file exists in a folder?
This is a way to see if any XML-files exists in that folder, yes.
To check for specific files use File.Exists(path)
, which will return a boolean indicating wheter the file at path
exists.
Use FileInfo.Exists
Property:
DirectoryInfo di = new DirectoryInfo(ProcessingDirectory);FileInfo[] TXTFiles = di.GetFiles("*.xml");if (TXTFiles.Length == 0){ log.Info("no files present")}foreach (var fi in TXTFiles) log.Info(fi.Exists);
or File.Exists
Method:
string curFile = @"c:\temp\test.txt";Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");