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!

volume label

Status
Not open for further replies.

rommeltm00

Programmer
Feb 16, 2006
56
PH
Sir/Mam:


how can i extract the volume label of the current drive

when i run it under dos it will be

vol > me.txt

volume label is put in this file me.txt

sample output

Volume in drive C is SYSTEM
Volume Serial Number is E460-6956

is there any vfp or winapi function for this

thanks
 
There is an M$ KB on this


Basically you use an API call to GetVolumeInformation

Code:
**---------------------------------------------------------------**
** Program: Getvol.prg                                           **
** Purpose: Demonstrates how to declare and use the Win32        **
**          GetVolumeInformation API.                           **
**---------------------------------------------------------------**
PUBLIC lpRootPathName, ;
        lpVolumeNameBuffer, ;
        nVolumeNameSize, ;
        lpVolumeSerialNumber, ;
        lpMaximumComponentLength, ;
        lpFileSystemFlags, ;
        lpFileSystemNameBuffer, ;
        nFileSystemNameSize

lpRootPathName           = "E:\"      && Drive and directory path
lpVolumeNameBuffer       = SPACE(256) && lpVolumeName return buffer
nVolumeNameSize          = 256        && Size of/lpVolumeNameBuffer
lpVolumeSerialNumber     = 0          && lpVolumeSerialNumber buffer
lpMaximumComponentLength = 256
lpFileSystemFlags        = 0
lpFileSystemNameBuffer   = SPACE(256)
nFileSystemNameSize      = 256

DECLARE INTEGER GetVolumeInformation IN Win32API AS GetVolInfo ;
        STRING  @lpRootPathName, ;
        STRING  @lpVolumeNameBuffer, ;
        INTEGER nVolumeNameSize, ;
        INTEGER @lpVolumeSerialNumber, ;
        INTEGER @lpMaximumComponentLength, ;
        INTEGER @lpFileSystemFlags, ;
        STRING  @lpFileSystemNameBuffer, ;
        INTEGER nFileSystemNameSize

RetVal=GetVolInfo(@lpRootPathName, @lpVolumeNameBuffer, ;
                  nVolumeNameSize, @lpVolumeSerialNumber, ;
                  @lpMaximumComponentLength, @lpFileSystemFlags, ;
                  @lpFileSystemNameBuffer, nFileSystemNameSize)

**---------------------------------------------------------------**
** Return code values for file system flags. Return codes are    **
** shown in parentheses.                                         **
**---------------------------------------------------------------**
** FS_CASE_SENSITIVE     If this flag is set, the file system    **
**                       supports case-sensitive file names      **
**                       (0001h).                                **
**                                                               **
** FS_CASE_IS_PRESERVED  If this flag is set, the file system    **
**                       preserves the case of file names when   **
**                       it places a name on disk (0002h).       **
**                                                               **
** FS_UNICODE_ON_DISK    If this flag is set, the file system    **
**                       supports Unicode in file names as they  **
**                       appear on disk (0004h).                 **
**                                                               **
** FS_PERSISTENT_ACLS    If this flag is set, the file system    **
**                       preserves and enforces ACLs. For        **
**                       example, NTFS preserves and enforces    **
**                       ACLs, but HPFS and FAT do not (0008h)   **
**                                                               **
** FS_FILE_COMPRESSION   The file system supports file-based     **
**                       compression (0010h)                     **
**                                                               **
** FS_VOL_IS_COMPRESSED  The specified volume is a compressed    **
**                       volume; for example, a DoubleSpace      **
**                       volume (8000h)                          **
**---------------------------------------------------------------**
** The following information is pertinent to several of the      **
** listed flags:                                                 **
**---------------------------------------------------------------**
** The FS_VOL_IS_COMPRESSED flag is the only indicator of volume-**
** based compression. The file system name is not altered to     **
** indicate compression. This flag comes back set on a Double-   **
** Space volume, for example. With volume-based compression, an  **
** entire volume is either compressed or not compressed.         **
**                                                               **
** The FS_FILE_COMPRESSION flag indicates whether a file system  **
** supports file-based compression. With file-based compression, **
** individual files can be compressed or not compressed.         **
**                                                               **
** The FS_FILE_COMPRESSION and FS_VOL_IS_COMPRESSED flags are    **
** mutually exclusive; both bits cannot come back set.           **
**---------------------------------------------------------------**
** Note that the return value can be a combination of the        **
** individual return values. For example, a return value of 6    **
** indicates that case is preserved (FS_CASE_IS_PRESERVED) and   **
** the file system supports UNICODE in file names                **
** (FS_UNICODE_ON_DISK).                                         **
**---------------------------------------------------------------**

DEFINE WINDOW ShowInfo FROM 0,0 TO 10,70 ;
                       FLOAT CLOSE ;
                       TITLE "Drive Information for " + ;
                       ALLTRIM(lpRootPathName) ;
                       FONT "Courier",10

ACTIVATE WINDOW ShowInfo
MOVE WINDOW ShowInfo CENTER

**--------------------------------------------------------------**
** Because several of the return values are padded with a null  **
** terminator, you will need to strip off the null terminator   **
** in order to get the correct value, which is what is done     **
** using the LEFT, ALLTRIM, and LEN functions.                  **
**--------------------------------------------------------------**
@ 0,1 SAY "Drive & path name            : " + ;
   ALLTRIM(lpRootPathName)

@ 1,1 SAY "Volume name                  : " + ;
   LEFT(ALLTRIM(lpVolumeNameBuffer),LEN(ALLTRIM(lpVolumeNameBuffer))-1)

@ 2,1 SAY "Max #/chars in vol name      : " + ;
   ALLTRIM(STR(nVolumeNameSize))

@ 3,1 SAY "Volume Serial #              : " + ;
   ALLTRIM(STR(lpVolumeSerialNumber))

@ 4,1 SAY "Max #/chars in dir/file names: " + ;
   ALLTRIM(STR(lpMaximumComponentLength))

@ 5,1 SAY "File System Flags            : " + ;
   ALLTRIM(STR(lpFileSystemFlags))

@ 6,1 SAY "File System type             : " + ;
   LEFT(ALLTRIM(lpFileSystemNameBuffer), ;
   LEN(ALLTRIM(lpFileSystemNameBuffer))-1)

@ 7,1 SAY "File Sys Name Size           : " + ;
   ALLTRIM(STR(nFileSystemNameSize))

** ----------------------------< End Code >-------------------------- **

If this code is run on an NTFS partition, the following would be typical
output:

Drive & Path name             : E:\ 
Volume name                   : Scratch
Max #/chars in vol name       : 256
Volume Serial #               : 484847074
Max #/chars in dir/file names : 255
File System Flags             : 31
File System Type              : NTFS
File System Name Size         : 256

The File System Flags value of 31 is a combination of the following file
system attributes:

Flag                      Hex Value   Decimal Value
---------------------------------------------------
FS_CASE_SENSITIVE             1             1
FS_CASE_IS_PRESERVED          2             2
FS_UNICODE_ON_DISK            4             4
FS_PERSISTENT_ACLS            8             8
FS_FILE_COMPRESSION          10            16
---------------------------------------------------
Total return value:                        31

Regards

Griff
Keep [Smile]ing
 
Or you can use VFP?
Code:
* One line answer 
lnDir2Dbf= ADIR(laFiles , "*" , "D")
*
*to save to a table sorted 
SELECT  0
IF FILE(DIRECTORY.DBF)
    ERASE DIRECTORY.DBF
ENDIF
CREATE TABLE (DIRECTORY.DBF") (NAME c(50), SIZE n(10,0), DATE d, TIME c(8), ATTRIB c(4), DIRECTORY c(50))
=ASORT(laFiles,1)
APPEND FROM array laFiles
BROWSE

David W. Grewe Dave
 
David,

How will that get him the volume label?

Regards

Griff
Keep [Smile]ing
 
From VFP Help ADIR()
Code:
Parameters
ArrayName
Specifies the name of the array. If the array you include doesn't exist, Visual FoxPro automatically creates the array. If the array exists and isn't large enough to contain all the information, Visual FoxPro automatically increases the size of the array to accommodate the information. If the array is larger than necessary, Visual FoxPro truncates the array. If the array exists and ADIR( ) returns 0 because no matching files are found, the array remains unchanged. If the array doesn't exist and ADIR( ) returns 0, the array isn't created.

The following table describes the contents and data type of each column in the array: 

Column  Array contents       Data type  
1       File names           Character
2       File sizes           Numeric
3       Dates last modified  Date
4       Times last modified  Character
5       File attributes      Character

The last array column contains the file attributes of the matching files. Each file attribute is expressed by a letter; a file can have more than one attribute. The following table indicates the file attribute represented by each letter: 

Letter  Attribute  
A       Archive – Read/Write 
H       Hidden
R       Read-only
S       System
D       Directory

cFileSkeleton
Specifies a file skeleton so you can store information about files with names or extensions that match a search criterion. For example, the criterion can be all tables, all text files, all files with names that have A as their first letter, and so on. Such general searches are done by including the wildcards * and ? in cFileSkeleton. A question mark represents a single character; an asterisk represents any number of characters. You can use any number of wildcards in any position within the file skeleton.

You can specify a drive and/or directory to search for matching file names. If you don't specify a drive and a directory, Visual FoxPro places information about files in the current directory into the array. 

cAttribute
Specifies the inclusion of subdirectories and hidden or system files.

cAttribute can contain any combination of D, H, and S. Including D returns subdirectory names of the current directory in addition to file names that match the file skeleton specified in cFileSkeleton. Including H returns information about hidden files that match the file skeleton specified in cFileSkeleton. Including S returns information about system files that match the file skeleton specified in cFileSkeleton. 

Include an empty string in cFileSkeleton to return just subdirectory names, hidden files or system files. 

You can include V in cAttribute to return the volume name of the current drive. Only the volume name is returned to the array if V is included with D, H, or S. The volume name is stored in the first array element and the remainder of the array is truncated.

David W. Grewe Dave
 
DelTables("DRIVES")
Griff,
Your right, I Cut and pasted the wrong part of my Routine

Code:
SELECT  0
CREATE TABLE (pcLocal+"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 
lnDir2Dbf= RECCOUNT()
USE IN DRIVES

David W. Grewe Dave
 
Ah, new trick to me, well done

So he could get the volume name like this:
Code:
adir(myArray,"c:\","V")
? myArray[1]

Regards

Griff
Keep [Smile]ing
 
That's available in my first (rather long winded) example, it ends up in lpVolumeSerialNumber

Regards

Griff
Keep [Smile]ing
 
sir griff

the output of serial number using your long winded routine is -463443626 instead of E460-6956

as in this result of run vol>me.txt

Volume in drive C is SYSTEM
Volume Serial Number is E460-6956
 
Weeeelll, I did just cut and paste the example from the M$ KB article... I did kinda expect it to work, but it is from M$, so you should expect a few abnormalities!

B-)

Regards

Griff
Keep [Smile]ing
 
I suspect the function is returning a decimal number and the thing you are seeing from Vol > is a hex representation - in which case you could try converting it.

I cut and pasted it into windows calculator and got the answer you are looking for, so that seems appropriate.



Regards

Griff
Keep [Smile]ing
 


thank you very much for all your response

God Bless and more power
 
? TRANSFORM(-463443626,"@0x")


Regards

Griff
Keep [Smile]ing
 
sir griff

well the return value of that was hex

i just tried it and bingo

thanks
 
Great, good luck.

The 'Sir Griff' is not needed 'Captain Griff' would suffice... B-)

Regards

Griff
Keep [Smile]ing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top