I'm Currently inside a for loop which iterates through a set of folders and obtains some required values from a JSON file. I also want to get the absolute path to each of those files.
Currently I tried approaches such as
string currentDir = AppDomain.CurrentDomain.BaseDirectory; string currentDir = Directory.GetCurrentDirectory();
Both of these gave me location to the debug file
what I want is the location of the Folder in which this file is existing rather .
Below is the code segment to which I hope to include this new code.
string rootDirectory = fbd.SelectedPath;
var foundFiles = Directory.EnumerateFiles(rootDirectory, "server.config", SearchOption.AllDirectories);
foreach (var file in foundFiles) { RepositoryHomeSettingsModel repositoryHomeSettingsModel = JsonConvert.DeserializeObject(File.ReadAllText(file));
string Name = SettingsModel.name;
}
Please find below possible ans,Do you require the same ?
var foundFiles = Directory.EnumerateFiles(rootDirectory, "*.txt", SearchOption.AllDirectories);
foreach (var file in foundFiles)
{
var folderpath= Path.GetDirectoryName(file);
//RepositoryHomeSettingsModel repositoryHomeSettingsModel = JsonConvert.DeserializeObject(File.ReadAllText(file));
//string Name = SettingsModel.name;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.