Re: How to enumerate windows drives?
| From: | Tom Rogers | Date: | Sat, 20 Nov 2004 08:55:19 +0000 |
| Subject: | Re: How to enumerate windows drives? | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-5255@lists.php.net to get a copy of this message | ||
Hi,
Saturday, November 20, 2004, 6:34:59 PM, you wrote:
CW> Hi all
CW> Do you know a way of enumerating all windows drives from within php?
CW> One way would be to open a file dialog and read the directory list as
CW> the drives are attached there, but I don't want to rely on this.
CW> Regards/MfG,
CW> Christian Weiske
I use the win32api for this
<?php
dl("php_w32api.dll");
$api =& new win32;
$api->registerfunction("long GetLogicalDriveStrings
Alias GetLogicalDriveStrings
(long &BufferLength, string &Buffer)
From kernel32.dll");
$api->registerfunction("long GetLogicalDrives
Alias GetLogicalDrives ()
From kernel32.dll");
$drives = array();
$len = 105; // set the length your variable should have
$buffer = str_repeat("\0", $len+1); // prepare an empty string
if ($api->GetLogicalDriveStrings($len,$buffer)){
$drives = explode("\0",trim($buffer));
}elseif($drive_list = $api->GetLogicalDrives()){
for($i=1,$drv=ord('A');$drv<=ord('Z');$drv++){
if($drive_list & $i){
$drives[] = chr($drv).":\\";
}
$i = $i << 1;
}
}else{
echo "no drives found\n";
}
print_r($drives);
?>
Let me know if you want a working win32api.dll
(the one shipped with php segfaults)
--
regards,
Tom