Click to See Complete Forum and Search --> : List of every drives


guile
October 23rd, 2001, 06:16 AM
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...

lalitha
October 23rd, 2001, 06:34 AM
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

guile
October 23rd, 2001, 06:44 AM
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...

lalitha
October 23rd, 2001, 06:56 AM
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>)
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

John G Duffy
October 23rd, 2001, 07:42 AM
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

John G Duffy
October 23rd, 2001, 07:46 AM
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/
'KPDTeam@Allapi.net
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

guile
October 23rd, 2001, 08:04 AM
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...

John G Duffy
October 23rd, 2001, 08:14 AM
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

DSJ
October 23rd, 2001, 10:04 AM
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: KPDTeam@Allapi.net
'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