I am writing a small program in C#/.NET that reads input files as they
arrive from other processes. Therefore, it is perfectly reasonable for
a file to be busy while it is being deposited for use by my program.
FileStream inFile = null;
try {
inFile = new FileStream("myFilePath", FileMode.Open,
FileAccess.Read, FileShare.Non);
}
catch (IOException e) {
}
Does indeed catch a locked file exception.
My problem, though, is that it appears to also catch other errors. I
want to quietly proceed if I get a locked file exception, but record an
error to a log and skip the file when I get something other than a
locked file.
How do I differentiate between a locked file and other IOExceptions?