根据用户在控制台应用程序VB.NET中输入的修改日期搜索文件 [英] Search files based on the date modified entered by user in console application VB.NET
问题描述
在此先谢谢你
导入System.IO
模块Module3
Sub Main()
而True
'读取值。
Dim s作为DateTime = Console.ReadLine()
’测试该值。
如果s = File.GetLastWriteTime( path)然后
Dim p作为New Process()
p.StartInfo = New ProcessStartInfo( notepad.exe, path )
p.Start()
其他
Dim p作为New Process()
p.StartInfo = New ProcessStartInfo( notepad.exe , path2)
p.Start()
End If
'写入值。
Console.WriteLine(您输入 + s)
End While
End Sub
End Module
在代码段中,您不是要搜索文件,而是要设置的上次修改时间不是您所需要的
您将需要搜索每个文件,直到找到用户输入的修改日期信息:-
dim s为datetime = console.readline()
'目标目录
昏暗目录= C:\Users \Peter\Desktop\TestFolder\
每个文件名作为IO.Directory.GetFiles(directory, *,IO.SearchOption.AllDirectories)中的字符串$ b Dim fName作为字符串= IO.Path.GetExtension(文件名)
dim datemod作为字符串= File.GetLastWriteTime(目录和fname)
如果s = datemod那么
Dim p作为New Process()
p.StartInfo = New ProcessStartInfo( notepad.exe,d挑衅fname)
p.Start()
其他
'做其他事情
endif
next
您需要添加的内容是,如果找不到具有该变量的文件,该怎么办。
希望这会使您更进一步。
i been given a assignment to create one console application using VB.NET. The assignment will able to open the file that based on the date modified entered by user. can anyone help me to solve my problem. I'm new in vb.net and most of the tutorial are using C# . together i put the latest code i has already done but still if i put the date modified the error file will display .
Thank you in advance
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
in the code snippet you are not searching for a file you are setting the time last modified which isn't what you want to do.
you will need to search through each file until you find the date modified information which is inputted by the user:-
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
things that you will need to add are, what to do when it doesn't find a file with that variable.
hope this gets you a little further.
这篇关于根据用户在控制台应用程序VB.NET中输入的修改日期搜索文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!