I need to check if an xml file exists in the folder.
DirectoryInfo di = new DirectoryInfo(ProcessingDirectory);
FileInfo[] TXTFiles = di.GetFiles(\"*.xml\");
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.
This helped me:
bool fileExists = (System.IO.File.Exists(filePath) ? true : false);
Since nobody said how to check if the file exists AND get the current folder the executable is in (Working Directory):
if (File.Exists(Directory.GetCurrentDirectory() + @"\YourFile.txt")) {
//do stuff
}
The @"\YourFile.txt"
is not case sensitive, that means stuff like @"\YoUrFiLe.txt"
and @"\YourFile.TXT"
or @"\yOuRfILE.tXt"
is interpreted the same.