Function GetLargestFile(ByVal strDir As String, ByVal strPattern As String) As String
(From strFile In Directory.GetFiles(strDir, strPattern)
Let FileInfo = New FileInfo(strFile)
Order By FileInfo.Length Descending
That method uses Directory.GetFiles() to get all of the files from a directory.
For each file it finds, it creates a new FileInfo object.
The .Length property tells the file size.
It then sorts the FileInfo objects by size in descending order.
It then returns the name of the first one in that list.
All of that is wrapped into a function called GetLargestFile() that takes the name of the directory to look in and the types of files to find.
Assuming you have permission to all of the subdirectories, you could add something simple like this:
Dim strRoot As String = "c:\myPath\"
Dim lst_strDirs As List(Of String) = Directory.GetDirectories(strRoot, "*.*", SearchOption.AllDirectories).ToList()
lst_strDirs.ForEach(Sub(strDir) Console.WriteLine(GetLargestFile(strDir, "*.jpg")))
BUT you should change the .First() in the GetLargestFile() to .FirstOrDefault() if there could be empty directories in the path.
See this article in in MSDN that (although in C#) explains a recursive method and a non-recursive method if you don't have read permission to all subdirectories.
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"
I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:
Runtime run = Runtime.getRuntime();
Process pr = ...