Quote Originally Posted by Harsh Gupta
PS - I am waiting Hack
Patience my New Delhi friend, is a virtue.

This was written by Matt Hart
VB Code:
  1. Option Explicit
  2.  
  3. Private Const MAX_PATH = 260
  4. Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
  5.  
  6. Private Type FILETIME
  7.     dwLowDateTime As Long
  8.     dwHighDateTime As Long
  9. End Type
  10.  
  11. Private Type WIN32_FIND_DATA
  12.     dwFileAttributes As Long
  13.     ftCreationTime As FILETIME
  14.     ftLastAccessTime As FILETIME
  15.     ftLastWriteTime As FILETIME
  16.     nFileSizeHigh As Long
  17.     nFileSizeLow As Long
  18.     dwReserved0 As Long
  19.     dwReserved1 As Long
  20.     cFileName As String * MAX_PATH
  21.     cAlternate As String * 14
  22. End Type
  23.  
  24. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
  25. (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
  26.  
  27. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" _
  28. (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
  29.  
  30. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
  31.  
  32. Private Type DirInfo
  33.     DirName     As String
  34. End Type
  35.  
  36. Private bCancel As Boolean
  37.  
  38. Private Sub FindDirs(D$, T As TreeView)
  39.     Static bFirstIn As Boolean
  40.    
  41.     If bCancel Then Exit Sub
  42.    
  43.     Dim nx As Node, C$
  44.     Dim N As Integer, Srch$, i As Integer, NewD$
  45.    
  46.     C$ = D$
  47.     If Right$(C$, 1) <> "\" Then C$ = C$ & "\"
  48.    
  49.     If Not bFirstIn Then
  50.         bFirstIn = True
  51.         Set nx = T.Nodes.Add(, , C$, C$)
  52.     End If
  53.    
  54.     Srch$ = C$ & "*.*"
  55.     ReDim Dees(1 To 10) As DirInfo
  56.     Call LoadDirs(Dees(), N, Srch$)
  57.    
  58.     DoEvents
  59.    
  60.     If N Then
  61.         For i = 1 To N
  62.             Set nx = T.Nodes.Add(C$, 4, Dees(i).DirName, LastPath$(Left$(Dees(i).DirName, Len(Dees(i).DirName) - 1)))
  63.         Next
  64.     Else
  65.         Exit Sub
  66.     End If
  67.    
  68.     For i = 1 To N
  69.         NewD$ = RTrim$(Dees(i).DirName)
  70.         Call FindDirs(NewD$, T)
  71.     Next
  72. End Sub
  73.  
  74. Private Function LastPath$(P$)
  75.     Dim i
  76.     For i = Len(P$) To 1 Step -1
  77.         If Mid$(P$, i, 1) = "\" Then
  78.             LastPath$ = Mid$(P$, i + 1)
  79.             Exit For
  80.         End If
  81.     Next
  82. End Function
  83.  
  84. Private Sub LoadDirs(D() As DirInfo, N As Integer, Srch$)
  85.     Dim a$, Max As Integer, i As Integer, k As Integer, W32 As WIN32_FIND_DATA, fHandle As Long, lResult As Long
  86.     Dim oPath$
  87.     Max = UBound(D)
  88.     N = 0
  89.    
  90.     oPath$ = Left$(Srch$, Len(Srch$) - Len(LastPath$(Srch$)))
  91.    
  92.     fHandle = FindFirstFile(Srch$, W32)
  93.  
  94.     If fHandle Then
  95.         Do
  96.             a$ = Left$(W32.cFileName, InStr(W32.cFileName, Chr$(0)) - 1)
  97.             If a$ <> "." And a$ <> ".." And ((W32.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) > 0) Then
  98.                 N = N + 1
  99.                 If Max < N Then
  100.                     Max = Max + 10
  101.                     ReDim Preserve D(1 To Max) As DirInfo
  102.                 End If
  103.                 D(N).DirName = oPath$ & a$ & "\"
  104.             End If
  105.             DoEvents
  106.             If bCancel Then Exit Do
  107.             lResult = FindNextFile(fHandle, W32)
  108.         Loop While lResult
  109.         lResult = FindClose(fHandle)
  110.     End If
  111.    
  112.     If bCancel Then Exit Sub
  113.  
  114.     For i = 1 To N - 1
  115.         For k = i + 1 To N
  116.             If UCase$(D(i).DirName) > UCase$(D(k).DirName) Then
  117.                 a$ = D(k).DirName
  118.                 D(k).DirName = D(i).DirName
  119.                 D(i).DirName = a$
  120.             End If
  121.         Next
  122.     Next
  123. End Sub
  124.  
  125. Private Sub Command1_Click()
  126.     Static Done
  127.     If Done Then Exit Sub
  128.     Done = True
  129.     bCancel = False
  130.     Command1.Caption = "Cancel"
  131.     Call FindDirs("C:\", TV)
  132.     Command1.Caption = "Fill It!"
  133.     MsgBox "Done!"
  134.     Done = False
  135. End Sub