查找最新文件和类型的C#代码
对不起,伙计们…第一个帖子在这里。刚刚掌握了这个网站的窍门。谢谢你迄今为止的帮助。由于“”的存在,我现在已通过第一个错误。现在,程序运行,但不会写入App.config文件以更新文件名查找最新文件和类型的C#代码,c#,file,C#,File,对不起,伙计们…第一个帖子在这里。刚刚掌握了这个网站的窍门。谢谢你迄今为止的帮助。由于“”的存在,我现在已通过第一个错误。现在,程序运行,但不会写入App.config文件以更新文件名 private static bool FindAndNoteMostRecentMsl() { // Get files from directory Console.WriteLine("Finding log file"); string l
private static bool FindAndNoteMostRecentMsl()
{
// Get files from directory
Console.WriteLine("Finding log file");
string logsFilePath = ConfigurationManager.AppSettings["LogFilePath"];
DirectoryInfo directory = new DirectoryInfo(logsFilePath);
FileInfo mostRecentMslFile = (from file in directory.GetFiles()
where file.Extension.ToLower() == "msl"
orderby file.CreationTime descending
select file).FirstOrDefault();
// 1) update name of most recent MSL in config
UpdateAppSettingValue("CurrentMslFileName", "mostRecentMslFile.Name");
// If nothing found, exits the program
if (mostRecentMslFile == null)
Console.WriteLine("...File not found...");
return false;
// If most recent MSL matches value in App.config, does nothing
string mslFileNameInConfig = ConfigurationManager.AppSettings["CurrentMslFileName"];
if (mslFileNameInConfig == mostRecentMslFile.Name)
return true;
// 2) reset counter in config
UpdateAppSettingValue("CurrentErrorCounter", "0");
return true;
}
您可能有输入错误,您想使用变量
logsFilePath
而不是“logsFilePath”
:
您可能有输入错误,您想使用变量
logsFilePath
而不是“logsFilePath”
:
为什么不复制并粘贴您看到的错误,并准确地告诉我们它发生在哪一行。这是一项技能,你必须学会自己解决这类问题,如果你需要帮助,你需要提供更精确的错误信息。为什么不复制和粘贴你看到的错误,并告诉我们它发生在哪一行。这是一项技能,你必须学会自己解决这类问题,如果你需要帮助,你需要提供更精确的错误信息。你意识到你可以正确编辑问题吗?你意识到你可以正确编辑问题吗?
DirectoryInfo directory = new DirectoryInfo("logsFilePath");
-->
DirectoryInfo directory = new DirectoryInfo(logsFilePath);