text: public static bool IndexExists(Directory directory){string[] files;try{files = directory.ListAll();} catch (DirectoryNotFoundException nsde) {return false;}if (files != null){string prefix = IndexFileNames.SEGMENTS + "_";foreach (string file in files){if (file.StartsWith(prefix, StringComparison.Ordinal) || file.Equals(IndexFileNames.SEGMENTS_GEN, StringComparison.Ordinal)){return true;}}}return false;}