Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ


How can I convert a mapped drive to UNC path or determine type of drive? by dbMark
Posted: 1 Jun 11 (Edited 1 Jun 11)

This FAQ was inspired by FAQ184-3137: How can I convert from a mapped drive to UNC path? when I was looking for ways to identify my network mapped drives as well as other drives that I might have connected.  In browsing I found a MS article describing how various types of drives can be identified.  The result is below.

If the program determines it is not a network mapped drive, then it drills deeper to distinguish between floppy/flash, hard drive, network, optical, RAM or other drive.


FUNCTION MappedDriveToUNC(cDrivePath)
    * support.microsoft.com/kb/135818 -- How to List Available Drives A-Z from Visual FoxPro
    LOCAL lcDrive, lcPath, lcUNC, lnUNCMaxSize, lnResult, lcRtnVal
    IF VARTYPE(cDrivePath)="C" AND ISALPHA(cDrivePath) AND IIF(LEN(cDrivePath)<=2 OR SUBSTR(cDrivePath,2,2)=":\",.T.,.F.)
        lnResult = -1
        lcDrive = UPPER(LEFT(cDrivePath,1))+":"
        lcDrvType = DRIVETYPE(lcDrive)
        lcPath = SUBSTR(cDrivePath,3)
        IF lcDrvType = 4  && network or removable drive
            lnUNCMaxSize = 400
            lcUNC = SPACE(lnUNCMaxSize)
            * lnResult values:
            * #DEFINE NO_ERROR                     0
            * #DEFINE ERROR_BAD_DEVICE          1200
            * #DEFINE ERROR_EXTENDED_ERROR      1208
            * #DEFINE ERROR_MORE_DATA            234
            * #DEFINE ERROR_NOT_SUPPORTED         50
            * #DEFINE ERROR_NO_NET_OR_BAD_PATH  1203
            * #DEFINE ERROR_NO_NETWORK          1222
            * #DEFINE ERROR_NOT_CONNECTED       2250 <-- typical error for non-UNC drive mappings
            * Declare, call and clear the DLL
            DECLARE INTEGER WNetGetConnection IN WIN32API AS ConvDrvToUNC STRING @lcDrive, STRING @lcUNC, INTEGER @lnUNCMaxSize
            lnResult = ConvDrvToUNC(@lcDrive, @lcUNC, @lnUNCMaxSize)
            CLEAR DLLS "ConvDrvToUNC"
        DO CASE
            CASE EMPTY(lnResult)
                lcRtnVal = ALLTRIM(LEFT(lcUNC,AT(CHR(0), lcUNC)-1)) + lcPath  && ALLTRIM() may not be needed
            CASE lcDrvType <> 4 OR lnResult = 2250
                * Invalid network resource
                lcRtnVal = "Drive "+lcDrive+" "+ ;
                            ICASE(lcDrvType=0,"does not exist",lcDrvType=1, "is not mapped or has no root directory", ;
                                    lcDrvType=2,"is a floppy or flash disk", lcDrvType=3,"is a hard disk", ;
                                    lcDrvType=4,"is a network or removable drive", lcDrvType=5,"is a CD-ROM drive", ;
                                    lcDrvType=6,"is a RAM disk", "is an unexpected drive type")+"."
                lcRtnVal = "Invalid system response. Win32Api Error #"+LTRIM(STR(lnResult))
        lcRtnVal = IIF(LEN(cDrivePath)<3,"Invalid drive letter.","Invalid path - Path must contain initial backslash.")
    RETURN lcRtnVal

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close