帮助打开文件夹中的最新文件 [英] help opening the most current file in a folder

查看:100
本文介绍了帮助打开文件夹中的最新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用hp的名为openview的软件程序,该程序在我们所有的计算机上提供并安装软件.每次运行软件连接时,它都会创建这些日志,我必须打开并浏览,并且厌倦了必须先搜索然后再打开的情况.

现在我已经使用下面的代码来获取所有具有* _mach.log的文件.我需要从该列表中获取帮助,并打开前面具有最高编号的列表.因此,正常的日志文件看起来像是20120516_mach.log,并且您看到的数字是该文件的创建日期,这也使我们知道上一次软件连接的运行时间.

我一直在使用下面的代码来获取文件名,而我真正想要做的是一旦它拥有最新的日志,便可以使用记事本打开它.现在下面的代码我现在要进入列表视图,并且我不想在最终结果中使用它.我想要的是当您单击按钮以打开日志时,它将在记事本中打开最新文件.

搜索文件夹的代码:

I have been working with a software program from hp called openview and it delivers and installs software on all our computers. It creates these logs each time it runs a software connect and I have to open and look through and im tired of having to search for it and then open it.

now i have deen using the below code to get all the files that have *_mach.log. I need help going from that list and open the one that has the highest number in front of it. so a normal log file looks like this 20120516_mach.log, and the numbers you see are the date it was created which also lets us know when a software connect last ran.

i have been using the below code to just get the file names and what i really want to do is once it has the most current log is to open it with notepad. now the below code i have going to a list view for right now and i don''t want to use it in the end result. What i want is when you click the button to open the log it opens the most current file in notepad.

code for searching the folder:

Dim di As New IO.DirectoryInfo("C:\Users\Zachary\Desktop\Log")
Dim diar1 As IO.FileInfo() = di.GetFiles("*_mach.log")
Dim dra As IO.FileInfo

'list the names of all files in the specified directory
For Each dra In diar1
    ListBox1.Items.Add(dra)
Next




我用于使用记事本打开文件的代码:(示例)




the code i m using to open files with notepad:(example)

Process.Start("notepad.exe", "\\" & strcomputer & "\C$\Windows\System32\drivers\etc\HOSTS")




帮助会很棒...




help would be great...

推荐答案

\ Windows \ System32 \ drivers \ etc \ HOSTS)
\Windows\System32\drivers\etc\HOSTS")




帮助会非常有用...




help would be great...


可能您的意思是最新文件".最近创建或最近写的?

System.IO.FileInfo实例的形式获取所有有问题的文件后,可以使用System.IO.CreationTimeSystem.IO.LastWriteTime(取决于所需的时间)并比较时间.请参阅:
http://msdn.microsoft.com/en-us/library/system.io. fileinfo.aspx [^ ].

请记住,时间分辨率不高,是毫秒.请参阅:
http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/bed97747-923d-4078-9ae3-04e0b0192342 [ http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ].

—SA
Probably you mean "most recent file". Most recently created or most recently written?

After you get all files in question in the form of the instance of System.IO.FileInfo, you can use System.IO.CreationTime or System.IO.LastWriteTime (depending on what time do you need) and compare time. Please see:
http://msdn.microsoft.com/en-us/library/system.io.fileinfo.aspx[^].

Remember that the time resolution is not high, it''s a millisecond. Please see:
http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/bed97747-923d-4078-9ae3-04e0b0192342[^].

By the way, many are confused about how to compare the instances of System.DateTime. The answer is simple: use the operator "<" or ">". Please see:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

—SA


这篇关于帮助打开文件夹中的最新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆