note 100886 modified in class.com by danbrown
| From: | danbrown@php.net | Date: | Sat, 13 Nov 2010 15:12:35 +0000 |
| Subject: | note 100886 modified in class.com by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173997@lists.php.net to get a copy of this message | ||
This script reports all Windows drives, drive type, status (if not available), free space and total
drive size:
<?php
$fso = new COM('Scripting.FileSystemObject');
$D = $fso->Drives;
$type =
array("Unknown","Removable","Fixed","Network","CD-ROM","RAM
Disk");
foreach($D as $d ){
$dO = $fso->GetDrive($d);
$s = "";
if($dO->DriveType == 3){
$n = $dO->Sharename;
}else if($dO->IsReady){
$n = $dO->VolumeName;
$s = file_size($dO->FreeSpace) . " free of: " . file_size($dO->TotalSize);
}else{
$n = "[Drive not ready]";
}
echo "Drive " . $dO->DriveLetter . ": - " . $type[$dO->DriveType] .
" - " . $n . " - " . $s . "<br>";
}
function file_size($size)
{
$filesizename = array(" Bytes", " KB", " MB", " GB",
" TB", " PB", " EB", " ZB", " YB");
return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] :
'0 Bytes';
}
?>
There are a number of other properties of the drive object which can be called this way - see:
http://msdn.microsoft.com/en-us/library/ts2t8ybh%28VS.85%29.aspx
--was--
This script reports all Windows drives, drive type, status (if not available), free space and total
drive size:
<?php
$fso = new COM('Scripting.FileSystemObject');
$D = $fso->Drives;
$type =
array("Unknown","Removable","Fixed","Network","CD-ROM","RAM
Disk");
foreach($D as $d ){
$dO = $fso->GetDrive($d);
$s = "";
if($dO->DriveType == 3){
$n = $dO.Sharename;
}else if($dO->IsReady){
$n = $dO->VolumeName;
$s = file_size($dO->FreeSpace) . " free of: " . file_size($dO->TotalSize);
}else{
$n = "[Drive not ready]";
}
echo "Drive " . $dO->DriveLetter . ": - " . $type[$dO->DriveType] .
" - " . $n . " - " . $s . "<br>";
}
function file_size($size)
{
$filesizename = array(" Bytes", " KB", " MB", " GB",
" TB", " PB", " EB", " ZB", " YB");
return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] :
'0 Bytes';
}
?>
http://php.net/manual/en/class.com.php