Skip to main content
Post Undeleted by NoName
added 6 characters in body
Source Link
NoName
  • 8.1k
  • 16
  • 62
  • 114

You can do like this:

static string FindConfig() { string appFolder = Path.GetDirectoryName(@"C:\DEV\root\project01\bin\release\project01.exe");  string configPath = null;  while (true)  {   Console.WriteLine(appFolder); if ( string[] files = Directory.EnumerateFilesGetFiles(appFolder, "*application.config", SearchOption.AllDirectories).Any; foreach (fvar =>file abcin files) { if (ffile.ToLower().EndsWith(@"\application.config"))   { configPath = appFolder + "\\application.config"; return file; break; }   } else  appFolder = Path.GetDirectoryName(appFolder);   if (appFolder.Length < 4) // "C:\" don't search root drive   { break;  } }break; if (configPath != null)  Console.WriteLine(configPath); ---------------------------  } static bool abc(string f) { } return f.ToLower().EndsWith("\application.config");configPath; } 

You can do like this:

string appFolder = Path.GetDirectoryName(@"C:\DEV\root\project01\bin\release\project01.exe"); string configPath = null; while (true) { Console.WriteLine(appFolder); if (Directory.EnumerateFiles(appFolder, "*application.config", SearchOption.AllDirectories).Any(f => abc(f))) { configPath = appFolder + "\\application.config"; break; } else appFolder = Path.GetDirectoryName(appFolder); if (appFolder.Length < 4) // "C:\" don't search root drive { break;  } } if (configPath != null)  Console.WriteLine(configPath); ---------------------------  static bool abc(string f) { return f.ToLower().EndsWith("\application.config"); } 

You can do like this:

static string FindConfig() { string appFolder = Path.GetDirectoryName(@"C:\DEV\root\project01\bin\release\project01.exe");  string configPath = null;  while (true)  {   Console.WriteLine(appFolder);  string[] files = Directory.GetFiles(appFolder, "*application.config", SearchOption.AllDirectories); foreach (var file in files) { if (file.ToLower().EndsWith(@"\application.config"))   {  return file;  }   }   appFolder = Path.GetDirectoryName(appFolder);   if (appFolder.Length < 4) // "C:\" don't search root drive   { break;  }  } return configPath; } 
Post Deleted by NoName
Source Link
NoName
  • 8.1k
  • 16
  • 62
  • 114

You can do like this:

string appFolder = Path.GetDirectoryName(@"C:\DEV\root\project01\bin\release\project01.exe"); string configPath = null; while (true) { Console.WriteLine(appFolder); if (Directory.EnumerateFiles(appFolder, "*application.config", SearchOption.AllDirectories).Any(f => abc(f))) { configPath = appFolder + "\\application.config"; break; } else appFolder = Path.GetDirectoryName(appFolder); if (appFolder.Length < 4) // "C:\" don't search root drive { break; } } if (configPath != null) Console.WriteLine(configPath); --------------------------- static bool abc(string f) { return f.ToLower().EndsWith("\application.config"); }