I have the following code that should recursively look for my file in the app's main directory, including subfolders:
public static List<string> FindFileInDirectory(string filename)
{
List<string> output = new List<string>();
try
{
foreach(string d in Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory))
{
foreach (string f in Directory.GetFiles(d, filename))
{
output.Add(f);
}
FindFileInDirectory(d);
}
}catch(System.Exception anyEx)
{
Debug.Print(anyEx.Message);
}
return output;
}
Could someone skilled guide me to get around this?
Error:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: The index pointed outside of the permitted range. The index can't be negative and has to be less than the collection's size.
Where it occurs:
I have a Mongoose
http server that's just an exe and I wish to find it within my directory to start it (if not running already). I include the constructor
of my class, there are only some fields for the ease of use in it. The problem is with the search that was found here.
The code for that is:
public MongooseHttpServer()
{
process = Process.GetProcessesByName("mongoose-free-6.5.exe");
if (process.Length == 0)
{
//http server not running, have to start
Debug.Print("not running, but starting now...");
process = new Process[1];
//in this case the first is enough.
mongooseLocation = DirectorySearcher.FindFileInDirectory("mongoose-free-6.5.exe")[0]; //error here.
process[0] = Process.Start(mongooseLocation ?? Directory.GetCurrentDirectory());
}
else
{
Debug.Print("already running");
}
}