Непосредственно перед попыткой найти файлы в каталоге сохраните имя каталога в переменной.Затем начните блок try для кода, который ищет в этом каталоге.Теперь у вас есть доступное имя каталога, если этот блок кода сгенерирован.
Например:
// ... somewhere in some method that's about to search a directory.
var dirName = directories[i]; // or something -- how do you get it before you pass it to DirectoryInfo?
try
{
SearchDirectory(dirName); // or a block of code that does the work
}
catch(Exception e)
{
// at this point, you know dirName. You can log it, add it to a list of erroring
// directories, or whatever. You could throw here, or swallow the error after logging it, etc.
}