使用Perl获取硬盘信息

时间:2010-08-19 07:17:04

标签: windows perl

我想使用perl检查 Windows 上的硬盘空间,有什么方法可以做到吗?

最诚挚的问候,

4 个答案:

答案 0 :(得分:8)

大多数情况下,Filesys::DfPortable等便携式解决方案是更好的选择。认识到virtuously lazy的机会。

答案 1 :(得分:6)

请参阅Win32::DriveInfo

($SectorsPerCluster, $BytesPerSector, $NumberOfFreeClusters, 
$TotalNumberOfClusters, $FreeBytesAvailableToCaller, $TotalNumberOfBytes, $TotalNumberOfFreeBytes) =  Win32::DriveInfo::DriveSpace( drive );

   $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.

答案 2 :(得分:1)

Win32 Drive Info应该可以解决问题。
我想你正在寻找

  

$ TotalNumberOfFreeBytes

答案 3 :(得分:0)

查询系统状态的另一种方法是使用Windows Management Interface查询DBD::WMI

以下查询应该为您提供有关磁盘空间的基本信息:

Select DeviceID,Size,FreeSpace from Win32_LogicalDisk