943,928 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 718
  • VB.NET RSS
Sep 22nd, 2008
0

c# to VB.Net

Expand Post »
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
foreach(string file in all_files)
{
//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++;
}
}
}
Reputation Points: 30
Solved Threads: 0
Junior Poster in Training
Elmo_loves_you is offline Offline
85 posts
since Mar 2008
Sep 22nd, 2008
0

Re: c# to VB.Net

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
Reputation Points: 155
Solved Threads: 41
Posting Whiz in Training
rapture is offline Offline
294 posts
since Jul 2007
Sep 22nd, 2008
0

Re: c# to VB.Net

That's your codes or get from internet?
vbnet Syntax (Toggle Plain Text)
  1. Private file_count As Integer = 0
  2. Public Sub GetDirectoryFileCount(ByVal dir As String)
  3. dir = dir & ”\”
  4. Dim all_files() As String=Directory.GetFileSystemEntries(dir)
  5. For Each file As String In all_files
  6. If Directory.Exists(file) Then
  7. GetDirectoryFileCount(file)
  8. Else
  9. file_count += 1
  10. End If
  11. Next file
  12. End Sub
Last edited by Jx_Man; Sep 22nd, 2008 at 12:43 pm.
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: counting how many text boxes have been modified
Next Thread in VB.NET Forum Timeline: Can it be done?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC