VB.NET 查找某路径下最新文件夹和最新的TXT文件

VB.NET 查找某路径下最新文件夹和最新的TXT文件

任务:得到最新文件夹下的最新TXT中的字符串

Dim MyFullPath As String

Dim MyFullPath1 As String

'排序文件夹,找时间最新的

 result_camera = "" '清空结果字符串

 MyFullPath = "D:\fluke17bnew\device_2013716\history"

‘查找history问价夹下的最新文件夹

  Dimdir As NewIO.DirectoryInfo(MyFullPath)

  DimNameList1 As List(OfString) = NewList(Of String)()

  DimCreateTimeList1 As List(Of System.DateTime) = New List(Of System.DateTime)()

   ForEach d AsIO.DirectoryInfo In dir.GetDirectories

   NameList1.Add(d.FullName)

   CreateTimeList1.Add(d.CreationTime)

   Next

 

   DimfileName1 As String()= NameList1.ToArray()

   DimfileCreageTime1 As System.DateTime() =CreateTimeList1.ToArray()

   Array.Sort(fileCreageTime1, fileName1)

    'MessageBox.Show("目录下最后一个建立的文件名称为:" + fileName1(fileName1.Length - 1) + vbCrLf + "建立时间为:" + fileCreageTime1(fileCreageTime1.Length - 1).ToString())

 'MsgBox(fileName1(fileName1.Length- 1))

 

 '排序文本文件,找时间最新的

 MyFullPath1 =fileName1(fileName1.Length - 1)

 Dimdi As DirectoryInfo = NewDirectoryInfo(MyFullPath1)

 Dimlist As List(OfFileInfo) = New List(OfFileInfo)(di.GetFiles())

  DimfileNameList As List(OfString) = NewList(Of String)()

  DimfileCreateTimeList As List(Of System.DateTime) = NewList(Of System.DateTime)()

  ForEach fi AsFileInfo In list

   fileNameList.Add(fi.Name)

   fileCreateTimeList.Add(fi.CreationTime)

  Next

 

  DimfileName As String()= fileNameList.ToArray()

  DimfileCreageTime As System.DateTime() =fileCreateTimeList.ToArray()

   Array.Sort(fileCreageTime,fileName)

   Dimfnn As Integer

  Dimaddr As String

 

  fnn = FreeFile()

  addr = MyFullPath1 & "\" & fileName(fileName.Length - 1)

   'DimOpF As New IO.FileStream(addr, IO.FileMode.Open)

   FileOpen(fnn, addr,OpenMode.Input)

  Input(fnn, result_camera)

  'OpF.Close()

   FileClose(fnn)

  MsgBox(result_camera)'str就是最后的结果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值