Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect a network drive? 1

Status
Not open for further replies.

Persmd

Programmer
May 21, 2003
38
0
0
US
Does anyone know how to detect the existence of network drives from within VFP 7.0 or 8.0, programatically?

What I would like to do is locate any mapped, or unmapped drives that might exist for a client computer from within a FoxPro program.

Thanks.

Michael
 
Hi Michael

I'm almost certain I've answered this question before (or one like it!). The basic thing is just to test for the drivetype of each letter from a to z...

Code:
for I = 0 to 25
  ? CHR(ASC("A")+I)+":",DriveType(CHR(ASC("A")+I)+":")
Next

1 - Unknown or no drive
2 - Floppy
3 - Local HDD
4 - Mapped Network Drive or Removeable one (ZIP)
5 - CD


Regards

Griff
Keep [Smile]ing
 
You can use the DIRECTORY function to determine whether a drive letter or path designation is valid, e.g.

? DIRECTORY("G")
? DIRECTORY("\\Drive_001\USERS\Target")
 
Thank you Griff. Your solution assumes that the drive is already mapped.

Thank you abelkin. Your solution assumes prior knowledge of the sharename \\Drive_001.

What I'm really looking for, is a way to drill down through "My Network Places" to get a list of the available (but not necessarily mapped) network drives, without user intervention.

Thanks again.

Michael
 
To get all the available shared folders use code like this:

Code:
close all
clear
set alte to c:\repfile.txt
set alte on
** use net View to put resources into a text file
! Net View > c:\res.txt
** read the text file
MyString = filetostr("c:\res.txt")
** scan the results
for X = 1 to memlines(MyString)
  ** where you have a network name...
  IF Left(Mline(MyString,X),2) = "\\"
    ** look for resources
    MyNetworkName = AllTrim(left(Mline(mystring,X),21))
    NoFolders = ANETRESOURCES(MyFolders,MyNetworkName,1)

    If NoFolders > 0
        ? "Shared Folders on "+MyNetworkName+": "
        for I = 1 to NoFolders
          ? Myfolders(I)
        Next
    else
        ? "No Shared Folders on : "+MyNetworkName
    endif
  Endif
Next X
set alte off
set alte to

This is based on an answer to another question today.

HTH

Regards

Griff
Keep [Smile]ing
 
Thanks Griff. That's exactly what I wanted!

Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top