VB.NET - How to display files and folders in vb.net

Asked By abinav shankar on 18-Nov-11 02:37 AM

Hi

I am using the folder browser option to select the folders but now my requirement is that I have to make it possible to deisplay both the files and folders in a list so that the user can select the one he wishes to, how to do it

Anil Kumar replied to abinav shankar on 18-Nov-11 03:49 AM
Hi Abhinav,

Below is the code to display folder and files within the folder both.

On Error Resume Next
  Dim fso, folder, files, NewsFile,sFolder
 
  Set fso = CreateObject("Scripting.FileSystemObject")
  sFolder = Wscript.Arguments.Item(0)
  If sFolder = "" Then
      Wscript.Echo "No Folder parameter was passed"
      Wscript.Quit
  End If
  Set NewFile = fso.CreateTextFile(sFolder&"\FileList.txt", True)
  Set folder = fso.GetFolder(sFolder)
  Set files = folder.Files
 
  For each folderIdx In files
    NewFile.WriteLine(folderIdx.Name)
  Next
  NewFile.Close

Do update us again
Thank you
Anil