extracting drive letter and its file system
hi there!
i wanted to know a way by which we can enlist all the drives available on the pc and then to be able to know its file system such as fat or ntfs..
thanks
[171 byte] By [
safeeullah] at [2007-11-17 22:39:12]

# 2 Re: extracting drive letter and its file system
There is no general way to it if that is what you are looking for. It is depending on the kind of API functions available.
For a windows system it would be the following...
#include <iostream>
using std::cout;
using std::endl;
// Get logical drives
DWORD dwLogicalDrives = ::GetLogicalDrives();
if(dwLogicalDrives)
{
for(int iCnt = 0; iCnt < 32; ++iCnt)
{
memset(szDriveRoot, 0, sizeof(szDriveRoot));
if(dwLogicalDrives & (1 << iCnt))
{
// Set drive root
sprintf(szDriveRoot, "%c:\\", iCnt + 'A');
// Determine partition type
UINT uiDriveType = ::GetDriveType(szDriveRoot);
switch(uiDriveType)
{
// Unknown
case DRIVE_UNKNOWN:
cout << "Partition " << szDriveRoot << " -> " << "Unknown" << endl;
break;
// Root path invalid
case DRIVE_NO_ROOT_DIR:
cout << "Partition " << szDriveRoot << " -> " << "Root path invalid"
<< endl;
break;
// Removable drive
case DRIVE_REMOVABLE:
cout << "Partition " << szDriveRoot << " -> " << "Removable drive"
<< endl;
break;
// Fixed drive
case DRIVE_FIXED:
{
cout << "Partition " << szDriveRoot << " -> " << "Fixed drive" << endl;
TCHAR szVolumeName[100] = "";
TCHAR szFileSystemName[10] = "";
DWORD dwSerialNumber = 0;
DWORD dwMaxFileNameLength = 0;
DWORD dwFileSystemFlags = 0;
if(::GetVolumeInformation(szDriveRoot,
szVolumeName,
sizeof(szVolumeName),
&dwSerialNumber,
&dwMaxFileNameLength,
&dwFileSystemFlags,
szFileSystemName,
sizeof(szFileSystemName)) == TRUE)
{
cout << "Volume name = " << szVolumeName << endl
<< "Serial number = " << dwSerialNumber << endl
<< "Max. filename length = " << dwMaxFileNameLength << endl
<< "File system flags = $" << hex << dwFileSystemFlags << endl
<< "File system name = " << szFileSystemName << endl;
}
break;
// Network drive
case DRIVE_REMOTE:
cout << "Partition " << szDriveRoot << " -> " << "Network drive" << endl;
break;
// CD-ROM
case DRIVE_CDROM:
cout << "Partition " << szDriveRoot << " -> " << "CD-ROM" << endl;
break;
// RAM-Disk
case DRIVE_RAMDISK:
cout << "Partition " << szDriveRoot << " -> " << "RAM-Disk" << endl;
break;
}
}
}
}