CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2000
    Location
    France, pas-de-calais (62), boulogne-sur-mer
    Posts
    26

    List of every drives

    Hi everyone,
    how could I get all the drives of my computer. In fact I know how to get physical drive (A:, C: ...) but I would like to find the folders like "Desktop", "My Computer", "Network neightbourghhood" "Recycled" in fact the special folders you can see in the combobox of word (file->open)

    Captain Guile never loose!! ... only when there's no opponents...

  2. #2
    Join Date
    Jul 1999
    Posts
    17

    Re: List of every drives

    Hi,

    You can make use of FileSystem object.

    Sample code:
    ============
    Dim filesys, drv, drvcoll, drvlist, vol
    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set drvcoll = filesys.Drives
    For Each drv In drvcoll
    drvlist = drvlist & drv.DriveLetter
    If drv.IsReady Then
    vol = drv.VolumeName
    End If
    If vol <> "" Then drvlist = drvlist & " ShareName: " & vol
    drvlist = drvlist & Chr(10)
    Next
    MsgBox drvlist

    Regards,
    Lalitha


  3. #3
    Join Date
    May 2000
    Location
    France, pas-de-calais (62), boulogne-sur-mer
    Posts
    26

    Re: List of every drives

    But how could I get the list of other "directories" or "folders" like Desktop, "My Computer", etc. You know with the tree like that

    Desktop
    \_ My Computer
    \_ A:
    \_ C:
    \_ D:
    \_ MyFolderOnDeskop
    ...
    ...




    Captain Guile never loose!! ... only when there's no opponents...

  4. #4
    Join Date
    Jul 1999
    Posts
    17

    Re: List of every drives

    If you want to get the list of folders you can make use of the same Filesystem object as below:

    Sample code
    ==================

    Dim filesys, demofolder, subfol, folcoll, folist
    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set demofolder = filesys.GetFolder(<DriveName got earlier&gt
    Set folcoll = demofolder.SubFolders
    For Each subfol in folcoll
    folist = folist & subfol.Name
    Next

    MsgBox follist


    You can't get for desktop and mycomputer. I donno how to do that.

    Regards,
    Lalitha


  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: List of every drives

    Desktop is a folder under C:\Windows. The rest like Recycle, My Computer and Network Neighborhood aren't real folders but system functions with special handling required by the system.

    John G

  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: List of every drives

    There is however a shBrowseForFOlder API that will produce a treeview like list of this stuff. Here is sample code.
    Start a new project. Paste this code into the general declarations section of the form. Run it.

    private Type BrowseInfo
    hWndOwner as Long
    pIDLRoot as Long
    pszDisplayName as Long
    lpszTitle as Long
    ulFlags as Long
    lpfnCallback as Long
    lParam as Long
    iImage as Long
    End Type
    Const BIF_RETURNONLYFSDIRS = 1
    Const MAX_PATH = 260
    private Declare Sub CoTaskMemFree Lib "ole32.dll" (byval hMem as Long)
    private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (byval lpString1 as string, byval lpString2 as string) as Long
    private Declare Function SHBrowseForFolder Lib "shell32" (lpbi as BrowseInfo) as Long
    private Declare Function SHGetPathFromIDList Lib "shell32" (byval pidList as Long, byval lpBuffer as string) as Long
    private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    '[email protected]
    Dim iNull as Integer, lpIDList as Long, lResult as Long
    Dim sPath as string, udtBI as BrowseInfo

    With udtBI
    'set the owner window
    .hWndOwner = me.hWnd
    'lstrcat appends the two strings and returns the memory address
    .lpszTitle = lstrcat("C:\", "")
    'Return only if the user selected a directory
    .ulFlags = BIF_RETURNONLYFSDIRS
    End With

    'Show the 'Browse for folder' dialog
    lpIDList = SHBrowseForFolder(udtBI)
    If lpIDList then
    sPath = string$(MAX_PATH, 0)
    'get the path from the IDList
    SHGetPathFromIDList lpIDList, sPath
    'free the block of memory
    CoTaskMemFree lpIDList
    iNull = InStr(sPath, vbNullChar)
    If iNull then
    sPath = Left$(sPath, iNull - 1)
    End If
    End If

    MsgBox sPath
    End Sub




    John G

  7. #7
    Join Date
    May 2000
    Location
    France, pas-de-calais (62), boulogne-sur-mer
    Posts
    26

    Re: List of every drives

    That is great, I could try to do something with it, but is there n.e. documentation on the shell32.dll?? In fact I would like to create my own drive combobox with images...
    If u know somewhere I could find some example. thx

    Captain Guile never loose!! ... only when there's no opponents...

  8. #8
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: List of every drives

    Shell32.dll is a real big animal and is the kernel for Windows Explorer functions. To many to mention in one place. Microsoft.com probably is the ultimate source for documentation but many VB Web sites have bits and pieces of the functions available in Shell32

    John G

  9. #9
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: List of every drives

    The following might be of interest/help in your indever...

    Const CSIDL_DESKTOP = &H0
    Const CSIDL_PROGRAMS = &H2
    Const CSIDL_CONTROLS = &H3
    Const CSIDL_PRINTERS = &H4
    Const CSIDL_PERSONAL = &H5
    Const CSIDL_FAVORITES = &H6
    Const CSIDL_STARTUP = &H7
    Const CSIDL_RECENT = &H8
    Const CSIDL_SENDTO = &H9
    Const CSIDL_BITBUCKET = &HA
    Const CSIDL_STARTMENU = &HB
    Const CSIDL_DESKTOPDIRECTORY = &H10
    Const CSIDL_DRIVES = &H11
    Const CSIDL_NETWORK = &H12
    Const CSIDL_NETHOOD = &H13
    Const CSIDL_FONTS = &H14
    Const CSIDL_TEMPLATES = &H15
    Const MAX_PATH = 260
    private Type SHITEMID
    cb as Long
    abID as Byte
    End Type
    private Type ITEMIDLIST
    mkid as SHITEMID
    End Type
    private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (byval hWnd as Long, byval szApp as string, byval szOtherStuff as string, byval hIcon as Long) as Long
    private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (byval hwndOwner as Long, byval nFolder as Long, pidl as ITEMIDLIST) as Long
    private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (byval pidl as Long, byval pszPath as string) as Long
    private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    'Show an about window
    ShellAbout me.hWnd, App.Title, "Created by the KPD-Team 1999", byval 0&
    'set the graphical mode to persistent
    me.AutoRedraw = true
    'print the folders to the form
    me.print "Start menu folder: " + GetSpecialfolder(CSIDL_STARTMENU)
    me.print "Favorites folder: " + GetSpecialfolder(CSIDL_FAVORITES)
    me.print "Programs folder: " + GetSpecialfolder(CSIDL_PROGRAMS)
    me.print "Desktop folder: " + GetSpecialfolder(CSIDL_DESKTOP)
    End Sub
    private Function GetSpecialfolder(CSIDL as Long) as string
    Dim r as Long
    Dim IDL as ITEMIDLIST
    'get the special folder
    r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
    If r = NOERROR then
    'Create a buffer
    Path$ = Space$(512)
    'get the path from the IDList
    r = SHGetPathFromIDList(byval IDL.mkid.cb, byval Path$)
    'Remove the unnecessary chr$(0)'s
    GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
    Exit Function
    End If
    GetSpecialfolder = ""
    End Function





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

Featured