473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Here is the sample code:

For Each strFile As String In My.Computer.FileSystem.GetFiles("c:\")
lstData.Items.Add(strFile)
If strFile.ToString.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,
Sep 17 '08 #1
1 1173
Teme64
10
Here you go:

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
Expand|Select|Wrap|Line Numbers
  1. Dim DirInfo As DirectoryInfo
  2. Dim Files() As FileInfo
  3. Dim OneFile As FileInfo
  4. Dim LargestSize As Long
  5. Dim LargestFile As String
  6.  
  7. LargestSize = -1
  8. LargestFile = ""
  9. DirInfo = New DirectoryInfo("C:\")
  10. Files = DirInfo.GetFiles("*.*", IO.SearchOption.TopDirectoryOnly)
  11. For Each OneFile In Files
  12.   If OneFile.Length > LargestSize Then
  13.     LargestSize = OneFile.Length
  14.     LargestFile = OneFile.FullName
  15.   End If
  16. Next
  17. If LargestSize > -1 Then
  18.   MessageBox.Show("Largest file is:'" & LargestFile & "' with size of " & LargestSize & " bytes", "Largest File", MessageBoxButtons.OK, MessageBoxIcon.Information)
  19. Else
  20.   MessageBox.Show("No files found in C:\", "Largest File", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  21. End If
No nested loops used...
Sep 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: chad | last post by:
I am writing a program to do some reliability calculations that require several nested for-loops. However, I believe that as the models become more complex, the number of required for-loops will...
4
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
2
by: Tim | last post by:
I have placed my assemblies in different folders (as per project req.). I am using config file with <codebase> option and registry with codebase option (COM Interop) to enable the runtime to locate...
7
by: mwt | last post by:
Is there a function in python that does what "locate" does in a bash shell? I know I could do it by using os.popen('locate'), but I'm curious if there's a Python "native" way to go about it....
19
by: (PeteCresswell) | last post by:
I'm going over an application written by somebody else and have encountered what looks to me like nested "With"s. Is this something new with MS Access 2003 or am I losing it? Seems to me that...
14
by: Jan Schmidt | last post by:
Hi, in a nested do-while-loop structure I would like to "continue" the outer loop. With goto this should be no problem in while-loops. However, for do-while I cannot get it to work (without a...
4
by: MDR | last post by:
Hello I have three "for" loops, two nested into the outer one and they depend on each other, like this: for (x=1; x<100; x++) { .... for (i=1; i<10; i++) {....} for (j=1; j<10;...
1
by: perlvasu | last post by:
6 jobs are running at the same time and accessing same dbm file for writing and reading. These are daily jobs and failing only some times not regularly. So i thought of this is just because of dead...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.