Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determining valid drives
Message
From
08/12/2006 15:07:25
 
 
To
08/12/2006 13:38:36
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01176193
Message ID:
01176238
Views:
10
>Hi all,
>
>I want to set something up on a form that will allow the user to select from a list of valid drives on the system (C:, F:, etc.). I'd like to do this with a listbox or a spinner.
>
>How can I determine what the valid drives would be? Once that's determined, how do I get a list of the valid folders on that drive?
>
>Thanks!
>
>John

This returns a string of drives letters and the type of drives they are.
    PROCEDURE DriveListing
        * Constants for drive types.
        #DEFINE DRIVE_UNKNOWN 0
        #DEFINE DRIVE_NO_ROOT_DIR 1
        #DEFINE DRIVE_REMOVABLE 2
        #DEFINE DRIVE_FIXED 3
        #DEFINE DRIVE_REMOTE 4
        #DEFINE DRIVE_CDROM 5
        #DEFINE DRIVE_RAMDISK 6
        *#DEFINE CR CHR(13)

        DECLARE INTEGER GetLogicalDrives IN Win32API
        DECLARE INTEGER GetDriveType IN Win32API STRING RootPath

        PRIVATE lcDrivestring, lcDriveRoot, liDrivelist, lcDrives, i
        lcDrives = ""

        liDrivelist = GetLogicalDrives()

        * Check each of the bits
        FOR i = 0 TO 31
            IF BITTEST(liDrivelist, i)
                * If the 0th bit is ON, that means drive 'A:',
                * the 2nd bit is 'C:", etc.
                lcDriveRoot = CHR(65 + i) + ":\"
                * Perform a GetDriveType to determine if it is a floppy, CD, etc.
                lcDrivetype = GetDriveType(lcDriveRoot)
                DO CASE
                    CASE lcDrivetype = DRIVE_UNKNOWN
                        lcDrivestring = "Cannot be determined"
                    CASE lcDrivetype = DRIVE_NO_ROOT_DIR
                        lcDrivestring = "Root directory does not exist"
                    CASE lcDrivetype = DRIVE_REMOVABLE
                        lcDrivestring = "Floppy/removable drive"
                    CASE lcDrivetype = DRIVE_FIXED
                        lcDrivestring = "Hard drive/nonremovable drive"
                    CASE lcDrivetype = DRIVE_REMOTE
                        lcDrivestring = "Remote/Network drive"
                        lcunc=THIS.GetUNCForDriveLetter(LEFT(lcDriveRoot,2))
                        IF TYPE('lcunc')="C" .AND. !EMPTY(lcunc)
                            lcDrivestring = lcunc
                        ENDIF
                    CASE lcDrivetype = DRIVE_CDROM
                        lcDrivestring = "CD-ROM drive"
                    CASE lcDrivetype = DRIVE_RAMDISK
                        lcDrivestring = "RAM disk"
                ENDCASE
                lcDrives = lcDrives + lcDriveRoot + " " + lcDrivestring + chr(13)+chr(10)
            ENDIF
        NEXT

        *=MESSAGEBOX(lcDrives, 0 + 64 + 0,'All Drives Listing')
        RETURN lcDrives
        RETURN

    ENDPROC
Greg Reichert
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform