HOW TO: Locate using nested loop the biggest file in ("c:\")

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gflor16
    New Member
    • Sep 2008
    • 9

    HOW TO: Locate using nested loop the biggest file in ("c:\")

    Here is the sample code:

    For Each strFile As String In My.Computer.Fil eSystem.GetFile s("c:\")
    lstData.Items.A dd(strFile)
    If strFile.ToStrin g.StartsWith("c :\IO") Then
    MessageBox.Show (strFile & " is in the root!")
    Exit For

    End If
    Next
    End Sub

    What can I change in that code to look up for the biggest file on the root.

    Thanks,
  • Teme64
    New Member
    • Sep 2008
    • 10

    #2
    Here you go:

    Code:
    Imports System.IO
    Code:
    Dim DirInfo As DirectoryInfo
    Dim Files() As FileInfo
    Dim OneFile As FileInfo
    Dim LargestSize As Long
    Dim LargestFile As String
    
    LargestSize = -1
    LargestFile = ""
    DirInfo = New DirectoryInfo("C:\")
    Files = DirInfo.GetFiles("*.*", IO.SearchOption.TopDirectoryOnly)
    For Each OneFile In Files
      If OneFile.Length > LargestSize Then
        LargestSize = OneFile.Length
        LargestFile = OneFile.FullName
      End If
    Next
    If LargestSize > -1 Then
      MessageBox.Show("Largest file is:'" & LargestFile & "' with size of " & LargestSize & " bytes", "Largest File", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
      MessageBox.Show("No files found in C:\", "Largest File", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    End If
    No nested loops used...

    Comment

    Working...