Click to See Complete Forum and Search --> : Listing Folders In A Network Location


softweng
July 5th, 2001, 02:00 PM
How Can I list all the folders in a network location without mapping a drive to the
location? For example we have a server named Delta. How can I list all the folders in the
location \\Delta\
I would also like to know the size of each folder.
Any help is greatly appreciated!!!

Kris
Software Engineer
Phoenix,AZ

John G Duffy
July 5th, 2001, 02:09 PM
Kris,
Enumerating folders in a remote computer is similar to a local computer except you need to supply the remote computers name and the Share name of the drive like so

option Explicit

private Sub Command1_Click()
Dim str
str = Dir("\\LAPTOP\C DRIVE\WINDOWS\*.*", vbNormal)
Do While str <> "" ' list all the files in windows folder
Debug.print str
str = Dir
Loop
End Sub



LAPTOP is the name of a remote computer and C Drive is the share name that was given it when the drive was set as sahared.



John G

softweng
July 5th, 2001, 03:58 PM
Is there a way to list all the share names on the pc. All I look at is the pc name i.e. \\Delta
All the folders are at that location but are actually shared folders on that server.
There is no drive name. So a folder named "John" would have a path like \\Delta\John\

Kris
Software Engineer
Phoenix,AZ

John G Duffy
July 5th, 2001, 04:24 PM
There probably is a way but I don't know how. Maybe someone else can help. I don't have the resources to reproduce that sort of environment.

John G

softweng
July 5th, 2001, 04:40 PM
I will keep looking for how to get the share names. I am using the current method to get all
the folder names given a path. Do you know how to get the folder sizes? I tried using FileLen
but since it is a directory it just returns "0" I can do it with the FileScriptingObject but it
takes a very long time where as the Dir function is quick.


private Sub GetAllFolders(sPath as string)
Dim FirstEntry as string

on error resume next

'//Make Sure Path Has A Trailing Backslash "\"
If Right(sPath, 1) <> "\" then sPath = sPath & "\"

'//Clear The List Box
List1.Clear

'//Retrieve The First Entry
FirstEntry = Dir(sPath, vbDirectory)

'//Loop Through All Entries And Find Folders Only
Do While FirstEntry <> ""
'//Ignore The Current Directory And The Encompassing Directory.
If FirstEntry <> "." And FirstEntry <> ".." then
'//Make Sure Entry is A Folder (Check Attributes)
If (GetAttr(sPath & FirstEntry) And vbDirectory) = vbDirectory then
'//Display Entries And Sizes
List1.AddItem FirstEntry & " --> " & FileLen(sPath & FirstEntry)
End If
End If

'//get The next Entry
FirstEntry = Dir
Loop

End Sub




Kris
Software Engineer
Phoenix,AZ

John G Duffy
July 6th, 2001, 07:17 AM
Look at this to see if it will help
http://www.planetsourcecode.com/xq/ASP/txtCodeId.23594/lngWId.1/qx/vb/scripts/ShowCode.htm
'
Also search on "Share Names" on Planet-Source-Code.com (without the quotes of course). You will get more than one hit.
Try Http://www.Freevbcode.com as another source.

John G