use Win32::DriveInfo;
($SectorsPerCluster, $BytesPerSector, $NumberOfFreeClusters, $TotalNumberOfClusters, $FreeBytesAvailableToCaller, $TotalNumberOfBytes, $TotalNumberOfFreeBytes) = Win32::DriveInfo::DriveSpace('f');
$TotalNumberOfFreeBytes = (Win32::DriveInfo::DriveSpace('c:'))[6];
$TotalNumberOfBytes = (Win32::DriveInfo::DriveSpace("\\\\serv\\share"))[5];
@drives = Win32::DriveInfo::DrivesInUse();
@freelet = Win32::DriveInfo::FreeDriveLetters();
$type = Win32::DriveInfo::DriveType('a');
($VolumeName, $VolumeSerialNumber, $MaximumComponentLength, $FileSystemName, @attr) = Win32::DriveInfo::VolumeInfo('g');
($MajorVersion, $MinorVersion, $BuildNumber, $PlatformId, $BuildStr) = Win32::DriveInfo::GetVersionEx();
The intention was to have a part of Dave Roth's Win32::AdminMisc functionality on Win95/98.
The current version of Win32::DriveInfo is available at:
http://www.dux.ru/guest/fno/perl/
($SectorsPerCluster, $BytesPerSector, $NumberOfFreeClusters, $TotalNumberOfClusters, $FreeBytesAvailableToCaller, $TotalNumberOfBytes, $TotalNumberOfFreeBytes) = Win32::DriveInfo::DriveSpace( drive );
drive - drive-letter in either 'c' or 'c:' or 'c:\\' form or UNC path in either "\\\\server\\share" or "\\\\server\\share\\" form. $SectorsPerCluster - number of sectors per cluster. $BytesPerSector - number of bytes per sector. $NumberOfFreeClusters - total number of free clusters on the disk. $TotalNumberOfClusters - total number of clusters on the disk. $FreeBytesAvailableToCaller - total number of free bytes on the disk that are available to the user associated with the calling thread, b. $TotalNumberOfBytes - total number of bytes on the disk, b. $TotalNumberOfFreeBytes - total number of free bytes on the disk, b.
Note: in case that UNC path was given first 4 values are undef.
Win 95 note: Win32 API GetDiskFreeSpaceEx() function that is realized by internal (not intended for users) GetDiskFreeSpaceEx() subroutine is available on Windows 95 OSR2 (OEM Service Release 2) only. This means build numbers ( $BuildNumber in GetVersionEx ( ) function, described here later) greater then 1000.
On lower Win95 builds $FreeBytesAvailableToCaller, $TotalNumberOfBytes, $TotalNumberOfFreeBytes are realized through the internal GetDiskFreeSpace() function that is claimed less trustworthy in Win32 SDK documentation.
That's why on lower Win 95 builds this function will return 7 undef's for UNC drives.
To say in short: don't use DriveSpace ( ) for UNC paths on early Win 95! Where possible use
net use * \\server\share
and then usual '\w:' syntax.
0 - the drive type cannot be determined. 1 - the root directory does not exist. 2 - the drive can be removed from the drive (removable). 3 - the disk cannot be removed from the drive (fixed). 4 - the drive is a remote (network) drive. 5 - the drive is a CD-ROM drive. 6 - the drive is a RAM disk. drive - drive-letter in either 'c' or 'c:' or 'c:\\' form or UNC path in either "\\\\server\\share" or "\\\\server\\share\\" form.
In case of UNC path 4 will be returned that means that networked drive is available (1 - if not available).
($VolumeName, $VolumeSerialNumber, $MaximumComponentLength, $FileSystemName, @attr) = Win32::DriveInfo::VolumeInfo ( drive );
drive - drive-letter in either 'c' or 'c:' or 'c:\\' form.
$VolumeName - name of the specified volume. $VolumeSerialNumber - volume serial number. $MaximumComponentLength - filename component supported by the specified file system. A filename component is that portion of a filename between backslashes. Indicate that long names are supported by the specified file system. For a FAT file system supporting long names, the function stores the value 255, rather than the previous 8.3 indicator. Long names can also be supported on systems that use the New Technology file system (NTFS). $FileSystemName - name of the file system (such as FAT or NTFS). @attr - array of integers 1-6 1 - file system preserves the case of filenames 2 - file system supports case-sensitive filenames 3 - file system supports Unicode in filenames as they appear on disk 4 - file system preserves and enforces ACLs (access-control lists). For example, NTFS preserves and enforces ACLs, and FAT does not. 5 - file system supports file-based compression 6 - specified volume is a compressed volume; for ex., a DoubleSpace volume
($MajorVersion, $MinorVersion, $BuildNumber, $PlatformId, $BuildStr) = Win32::DriveInfo::GetVersionEx ( );
$MajorVersion - major version number of the operating system. For Windows NT version 3.51, it's 3; for Windows NT version 4.0, it's 4.
$MinorVersion - minor version number of the operating system. For Windows NT version 3.51, it's 51; for Windows NT version 4.0, it's 0. $BuildNumber - build number of the operating system. $PlatformId - 0 for Win32s, 1 for Win95/98, 2 for Win NT $BuildStr - Windows NT: Contains string, such as "Service Pack 3". Indicates the latest Service Pack installed on the system. If no Service Pack has been installed, the string is empty. Windows 95: Contains a null-terminated string that provides arbitrary additional information about the operating system.
Aldo Calpini to use this module. Nothing is exported by default. All functions return undef on errors.
0.02 - Austin Durbin <adurbin@earthlink.net> tested module on Win NT and discovered small bug in UNC paths handling. Fixed. Thanks Austin! .
0.03 - fixed bug that returned incorrect values for volumes that are larger than 0xffffffff bytes (4GB). Approved on Win98 with FAT32.
April 6, 1999.
<blazer@mail.nevalink.ru>