文件存在时,GetLastWriteTime不准确

时间:2016-12-02 16:21:29

标签: vb.net

我正在尝试获取目录中文件的上次修改时间。我遍历目录并打印修改日期。输出显示10个文件(在其他文件夹上也使用不同数量的文件)。命令提示符中出现10个文件。所有这些都打印在12/31/1600。

我如何修复它以便打印正确的日期?

Dim strFilepath = "C:\Test" 'Test folder contains 10 files for test
Dim File As System.IO.FileInfo() = directory.GetFiles()
Dim File1 As System.IO.FileInfo
Dim strLastModified As String

For Each File1 In File 'Loops the GetLastWriteTime
    strLastModified = System.IO.File.GetLastWriteTime(strFilepath & File.ToString()).ToShortDateString()
    Console.WriteLine(strLastModified)'Prints all 10 files but with the 12/31/1600 date
    'Files do exist, code goes into file, it loops through it but wrong date.

0 个答案:

没有答案