Asp.net 根据用户在控制台应用程序VB.NET中输入的修改日期搜索文件
我被指派使用VB.NET创建一个控制台应用程序。分配将能够打开基于用户输入的修改日期的文件。有人能帮我解决我的问题吗。我是vb.net新手,大部分教程都使用C。我把我已经完成的最新代码放在一起,但是如果我把修改日期放在一起,错误文件就会显示出来 先谢谢你Asp.net 根据用户在控制台应用程序VB.NET中输入的修改日期搜索文件,asp.net,vb.net,date,console-application,Asp.net,Vb.net,Date,Console Application,我被指派使用VB.NET创建一个控制台应用程序。分配将能够打开基于用户输入的修改日期的文件。有人能帮我解决我的问题吗。我是vb.net新手,大部分教程都使用C。我把我已经完成的最新代码放在一起,但是如果我把修改日期放在一起,错误文件就会显示出来 先谢谢你 Imports System.IO Module Module3 Sub Main() While True ' Read value. Dim s As DateT
Imports System.IO
Module Module3
Sub Main()
While True
' Read value.
Dim s As DateTime = Console.ReadLine()
' Test the value.
If s = File.GetLastWriteTime("path") Then
Dim p As New Process()
p.StartInfo = New ProcessStartInfo("notepad.exe", "path")
p.Start()
Else
Dim p As New Process()
p.StartInfo = New ProcessStartInfo("notepad.exe", "path2")
p.Start()
End If
' Write the value.
Console.WriteLine("You typed " + s)
End While
End Sub
End Module
在代码段中,您不是在搜索一个文件,而是在设置上次修改的时间,这不是您想要做的 您需要搜索每个文件,直到找到用户输入的修改日期信息:-
dim s as datetime = console.readline()
'Target Directory
Dim directory = "C:\Users\Peter\Desktop\TestFolder\"
For Each filename As String In IO.Directory.GetFiles(directory, "*", IO.SearchOption.AllDirectories)
Dim fName As String = IO.Path.GetExtension(filename)
dim datemod as string = File.GetLastWriteTime(directory & fname)
If s = datemod Then
Dim p As New Process()
p.StartInfo = New ProcessStartInfo("notepad.exe", directory & fname)
p.Start()
Else
'do something else
endif
next
您需要添加的内容是,当它找不到包含该变量的文件时该怎么办
希望这能让您更进一步。您遇到了什么错误,在哪一行?如果您需要我们的帮助,您应该向我们提供我们帮助您所需的所有信息。你提到了一个错误。你不认为告诉我们错误是什么很重要吗?在代码文件的顶部添加Option Strict On或进入项目属性并启用Option Strict。Console.ReadLine返回一个字符串,但您正在将结果存储到DateTime变量中。