Results 1 to 3 of 3
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191

    Listing folders and files

    Hi Guy's hope everyone is staying safe and well



    The below code i have got adds folder names listing to another list box when i click (Listing folders only)

    Can this be adapted to add folder names and file names within the selected directory ? (wanting to list folders and files)

    Additional to this, is there a method of opening the file if it is a file you have clicked on or not opening if it is another directory ???

    ie: if extensions = "" then it's a folder or If extensions <> "" then Application.FollowHyperlink ?????

    Code:
        Dim fso As Object    Dim sf2 As Variant, fl2 As Variant
        Dim i As Integer
        Me.lstDir2.RowSource = "Value List"
        Me.lstDir2.RowSource = ""
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set fl2 = fso.GetFolder("T:\" & lstDir1 & "\")
        Set sf2 = fl2.SubFolders
        For Each fl2 In sf2
        i = i + 1
        Me.lstDir2.AddItem fl2.Name
        Next
        Me.lstDir2.Requery
    Last edited by DMT Dave; 04-20-2020 at 01:17 AM. Reason: Added an update

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    File explorer already does this. Why do you need it in a listbox?

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191
    Hi ranman256 thank you fro your reply

    so when the user clicks on the listing of folders to open another folder, lst1 is the main dir lst 1 refreshes lst2 with folders, lts3 so on

    if in lst1 lst2 or lst3 it is a file and not a folder, i want to then open that file which i can achieve, i just need to list files and folders and not just folders

    then pick up if it is a folder you have clicked on or a file

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-20-2018, 10:15 AM
  2. Replies: 3
    Last Post: 11-29-2017, 08:10 AM
  3. Replies: 4
    Last Post: 02-04-2017, 09:55 PM
  4. Importing a bulk of files from different folders
    By jangobango in forum Access
    Replies: 10
    Last Post: 03-07-2016, 04:30 PM
  5. Access collection of files and folders?
    By pctechtv in forum Access
    Replies: 1
    Last Post: 11-13-2011, 05:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums