0

Hi Guys,

Im more familiar with coding in C# ... can someone please help me to convert the line highlighted below into VB.NET

Much appreciated

private int file_count = 0;
///
/// Get the file count of a given directory recursively.
///
public void GetDirectoryFileCount(string dir)
{
dir = dir + @”\”;
//get all the directories and files inside a directory
String[] all_files=Directory.GetFileSystemEntries(dir);
//loop through all items
[B]foreach(string file in all_files)[/B]
{
//check to see if the file is a directory if not increment the count
if(Directory.Exists(file))
{
//recursive call
GetDirectoryFileCount(file);
}
else
{
//increment file count
file_count++;
}
}
}
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Jx_Man
0

If you declare file in advance it's just

Dim file As string

followed with

For Each file in all_files

At least that's how I normally do it

"For Each liListItem In ddlAssigned.Items" is how I've done it

0

That's your codes or get from internet?

Private file_count As Integer = 0
Public Sub GetDirectoryFileCount(ByVal dir As String)
  dir = dir & ”\”
  Dim all_files() As String=Directory.GetFileSystemEntries(dir)
  For Each file As String In all_files
    If Directory.Exists(file) Then
      GetDirectoryFileCount(file)
    Else
      file_count += 1
    End If
  Next file
End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.