Results 1 to 4 of 4

Thread: Directory Browsing

  1. #1
    Guest

    Question

    Hey there,
    really need some help here.
    Does anyone knows how to use VB to Browse for directories and files, like the "Explorer" in Windows?

    My purpose is to select a file from a certain directories then, send it to users, just like the ICQ thing.
    Can anyone help me out?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Simply you could use filelistbox, dirlistbox and drivelistbox. You could also develope a treestyle app like explorer using the tree. Commondialogbox is another simple solution.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Junior Member
    Join Date
    Mar 2000
    Location
    Montreal, QC
    Posts
    24

    Thumbs up

    Here you go, this should work:


    First add a "CommonDialog" Control to your form from the "Microsoft Common Dialog Control 6.0" component (I called it "dlgOpenFile" in the following code), and then use this code.

    Code:
    'Open file dialog box
    dlgOpenFile.Filter = "Executables (*.exe)|*.exe|" & _
    "Text Files (*.txt)|*.txt|" & _
    "All Files (*.*)|*.*" 'Change to match the files you want
    dlgOpenFile.DialogTitle = "Select a file"  'Window Title
    dlgOpenFile.Flags = _
      cdlOFNFileMustExist + _
      cdlOFNHideReadOnly + _
      cdlOFNLongNames + _
      cdlOFNExplorer
    dlgOpenFile.CancelError = True
    
    On Error Resume Next
    dlgOpenFile.ShowOpen            'Open File Dialog Window
                
    If Err.Number = cdlCancel Then  'The user canceled
       Exit Sub
    ElseIf Err.Number <> 0 Then     'Unknown error
                
       MsgBox "Error " & Format$(Err.Number) & _
       " selecting file." & vbCrLf & _
       Err.Description
       Exit Sub
            
    End If
    This will return a full path & Filename (i.e. "C:\AFolder\AFile.ext")

    Hope this helps!

    JMik

  4. #4
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    Paste this in the declarations section of a module:
    Code:
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Private Type BROWSEINFO
        hOwner As Long
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As Long
        lParam As Long
        iImage As Long
    End Type
    Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
    Private Const BIF_RETURNONLYFSDIRS = &H1
    and drop this somewhere in the module:
    Code:
    Public Function DialogSelectFolder(hOwner As Long, psTitle As String) As String
        Dim udtBrowseInfo As BROWSEINFO, sPath As String
        With udtBrowseInfo
            .hOwner = hOwner
            .pidlRoot = 0&
            .lpszTitle = psTitle
            .ulFlags = BIF_RETURNONLYFSDIRS
        End With
        sPath = Space$(512)
        If SHGetPathFromIDList(SHBrowseForFolder(udtBrowseInfo), sPath) Then
            DialogSelectFolder = Left(sPath, InStr(sPath, vbNullChar) - 1)
        Else
            DialogSelectFolder = ""
        End If
    End Function
    It returns the selected folder, or "" if cancel was pressed.
    Hope this helps

    Crazy D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width