vb.net - 在目录中查找最近的文件

标签 vb.net getfiles

我正在尝试从目录中加载最新的文件,但我的以下代码不起作用。我有什么明显的错误吗?!

Dim myFile = Directory.GetFiles("C:\Users\Joe\Desktop\XML Logs").OrderByDescending(Function(f) f.LastWriteTime).First()

我收到两条错误消息:

Data type(s) of the type parameter(s) in extension method 'Public Function OrderByDescending(Of TKey)(keySelector As System.Func(Of String, TKey)) As System.Linq.IOrderedEnumerable(Of String)' defined in 'System.Linq.Enumerable' cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.



和:

'LastWriteTime' is not a member of 'String'.

最佳答案

Directory.GetFiles() 返回 String() .

显然你的意思是 DirectoryInfo.GetFiles() 返回 FileInfo() .

关于vb.net - 在目录中查找最近的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9369902/

相关文章:

vb.net - 休眠VB.NET

asp.net - vb.net Webapi 项目中缺少 request.CreateResponse

c# - 在 C# 中对 Directory.GetFiles 的结果进行排序

f# - 在F#: How do I obtain a list of the filenames in a directory; expected unit have string中

c# - 如何在使用 GetFiles() 时排除某些文件

c# - C# 中的 Utils.CopyArray?

VB.NET别名(如C#)

c# - 如何使用 ffmpeg 为所有视频文件生成缩略图?

c# - UnauthorizedAccessException 无法解决 Directory.GetFiles 失败

c# - 在设计模式下进行编辑时 designer.vb 文件中的自定义代码消失