[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Grid and File list

I need to populate a grid with a list of files in one directory. How do i go about it?
0
eliasis
Asked:
eliasis
  • 2
1 Solution
 
wsh2Commented:
1. Open a New Standard.Exe Project
2. Add a FlexGrid to the form (MSFlexGrid1).
3. Set a reference (Vb Menu -> Project -> Reference) to the "Microsoft Scripting Runtime" (SCRRUN.DLL).
4. Copy and paste the following into your Form1 code window.
5. Change the Directory name to what ever you like.

<----- Code Begin ----->

Private Sub Form_Load()

  xFolderList ("c:\Windows") <---- CHANGE

End Sub

Private Sub xFolderList _
(ByVal strDirectory As String) _

  Dim fsoWork As FileSystemObject
  Dim fsoFolder As Folder
  Dim fsoFile As File
 
  Set fsoWork = CreateObject("Scripting.FileSystemObject")
  Set fsoFolder = fsoWork.GetFolder(strDirectory)
 
  MSFlexGrid1.Clear
  MSFlexGrid1.Cols = 5
  MSFlexGrid1.Rows = 0
  MSFlexGrid1.AddItem ( _
    "Line" & vbTab & _
    "Name" & vbTab & _
    "DateCreated" & vbTab & _
    "DateLastAccessed" & vbTab & _
    "DateLastModified" & vbTab)
 
  Dim intLine As Integer
  For Each fsoFile In fsoFolder.Files
    MSFlexGrid1.AddItem ( _
      intLine & vbTab & _
      fsoFile.Name & vbTab & _
      fsoFile.DateCreated & vbTab & _
      fsoFile.DateLastAccessed & vbTab & _
      fsoFile.DateLastModified & vbTab)
  Next fsoFile
 
  MSFlexGrid1.FixedRows = 1

End Sub

<----- Code End ----->
0
 
eliasisAuthor Commented:
wsh2, thank you
just to understand it better what is "Microsoft Scripting Runtime" (SCRRUN.DLL) being used for?
0
 
wsh2Commented:
Setting the reference, provides the SCRRUN.DLL interfaces so that you can use the File System Object class programming contained inside of it. In essence, rather than programming all the nuts and bolts of File System Access, you are hooking into a Microsoft program library that provides that functionality, and then using the methods and properties there to achieve what you want.. <smile>.

The main difference between a Component and a Reference is that a Component usually requires a form / graphical interface while a reference does not. As such.. FSO (SCRRUN.DLL) is just like a Microsoft Control, only it does not require a Graphical User interface.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now