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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting drive name 1

Status
Not open for further replies.

beedubau

Programmer
Jan 7, 2003
97
AU
I have a USB device ( Seagate ) which I have named SEATHUMB - thus I get "SEATHUMB(E:)" in My Computer.

Is it possible to get this name in VFP?

Regards

bryan
 
This does not return the name for Floppies, CD's, DVD's or items connected to the Computers HDD controller.

It might work for USB drives

close all
ERASE DRIVES.DBF
SELECT 0
CREATE TABLE ("DRIVES.DBF") (LETTER c(1), LABEL c(15))
FOR I = 65 TO 90
lnType = DRIVETYPE(CHR(i)+":")
IF lnType<>1
=ADIR(laFiles , chr(i)+":" , "DV")
APPEND BLANK
replace LETTER WITH CHR(i)
replace LABEL WITH laFiles(1)
ENDIF
ENDFOR
BROWSE

David W. Grewe Dave
 
Hi Dave,

it works for me, for every HDD or USB device I have given a Volume name. Nice, I did never use the V=Volume cAttribute of ADIR(). My C: drive is listed as "Local Drive (C:)", but it's volume name is empty, so it's okay, that ADIR() doesn't return that name.

Bye, Olaf.
 
Olaf,
Would you believe I wrote that back in the FPW2.6 days.

David W. Grewe Dave
 
I don't doubt the V attribute was there almost always, I just didn't used it.

Bye, Olaf.
 
You can also use the WinAPI WScript

*Variable pcDrive must be in the format "C:"
LPARAMETER pcDrive
STORE '' TO lcRetVal
DO CASE
CASE PARAMETERS()<1 OR VARTYPE(pcDrive)<>"C" OR EMPTY(pcDrive) OR LEN(pcDrive)<>2
CASE AT(":",pcDrive,1)<>2
OTHERWISE
LOCAL WshNetWork AS OBJECT
LOCAL oDrives AS OBJECT
WshNetWork=CREATEOBJECT("WScript.Network")
oDrives=WshNetWork.EnumNetworkDrives &&NOTE: This array is 0 based
FOR i=0 TO oDrives.COUNT-1 STEP 2
IF ALLTRIM(UPPER(oDrives.ITEM)) = pcDrive
lcRetVal=ADDBS(oDrives.ITEM[i+1])
EXIT
ENDIF
ENDFOR
ENDCASE
RETURN lcRetVal


David W. Grewe Dave
 
HI Dave,

I've implemented what I wanted with your first example - thank you - I could only get two drives ( the last on the list )with the second example.

I found

Code:
 Set WshNetwork = WScript.CreateObject("WScript.Network")
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1
    WScript.Echo clDrives.Item(i)
Next

on a page.

I wondered why you had COUNT-1 STEP 2.

The enumeration appeared not to work correctly on my PC.

Thanks

Bryan
 
VFP arrays by Default Start at 1.
The WScript array starts at 0.

So you have to look one element behind (or start i=-1).
The STEP 2 because the array is not a 2 dimensional but one.

Element 0 = Drive letter
Element 1 = Volume Name
Element 2 = Drive Letter
Element 3 = Volume NAme
Etc.




David W. Grewe Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top