I guess it depends on what you mean by "the current folder". Presumably you mean the folder in which your application was installed. If that's the case, then you can get the directory that your application lives in using this (note that you will need a reference to System.Reflection
to use the Assembly
class):
var thisExeDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Then, when you have that directory, you can search for folders underneath it using Directory.EnumerateDirectories
, passing in our exe path as the directory to search under, the directoryToFind
as the SearchPattern
, and SearchOption.AllDirectories
if you want to search sub-folders as well:
var directoryToFind = "Temp_Folder";
var result = Directory
.EnumerateDirectories(thisExeDirectory, directoryToFind, SearchOption.AllDirectories)
.FirstOrDefault();
if (result != null)
{
Console.WriteLine($"Found directory here:\n\"{result}\"");
}
// Wait for input before closing
Console.WriteLine("\nDone!\nPress any key to exit...");
Console.ReadKey();
Output

If you were actually looking for a File
instead of a Directory
, the code is mostly the same, except you'd use the Directory.EnumerateFiles
instead:
var fileToFind = "TextFile1.txt";
var result = Directory
.EnumerateFiles(thisExeDirectory, fileToFind, SearchOption.AllDirectories)
.FirstOrDefault();