Monday, April 30, 2012

How to Get Recursive Listing of Files and Directories in VB.NET


How to Get Recursive Listing of Files and Directories in VB.NET



 Public Shared Function getRecursiveListing(ByVal initial As String) As List(Of String)
' This list stores the results.
Dim result As New List(Of String)


' This stack stores the directories to process.
Dim stack As New Stack(Of String)


' Add the initial directory
stack.Push(initial)


' Continue processing for each stacked directory
Do While (stack.Count > 0)
   ' Get top directory string
   Dim dir As String = stack.Pop
   Try
' Add all immediate file paths
result.AddRange(Directory.GetFiles(dir, "*.*"))


' Loop through all subdirectories and add them to the stack.
Dim directoryName As String
For Each directoryName In Directory.GetDirectories(dir)
   stack.Push(directoryName)
Next


   Catch ex As Exception
   End Try
Loop


' Return the list
Return result
    End Function






Dim list As List(Of String) = getRecursiveListing("C:\YourDirectoryPath")


' Loop through and display each path.
For Each path In list
   Console.WriteLine(path)
Next



How to get Tablewise Rows or Records count in MySQL Database



How to get Tablewise Rows or Records count in MySQL Database following SQL / Query is used

SELECT table_name, table_rows
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_SCHEMA = 'your_database_Name' ; 


How to get record counts for all tables in MySQL Database

SELECT SUM(TABLE_ROWS) 
    FROM INFORMATION_SCHEMA.TABLES 
    WHERE TABLE_SCHEMA = 'your_database_Name' ; 










Friday, April 27, 2012

How to Get Filename from URL in VB.Net (Asp .Net)


Get Filename from URL


Public Function GetFileNameFromURL(ByVal URL As String) As String
        Try
            Return URL.Substring(URL.LastIndexOf("/") + 1)
        Catch ex As Exception
            Return URL
        End Try
End Function