note 47968 added to ref.filesystem
| From: | rupert at save9 dot com | Date: | Tue, 07 Dec 2004 16:43:25 +0000 |
| Subject: | note 47968 added to ref.filesystem | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81491@lists.php.net to get a copy of this message | ||
In response to requiring a list of accessible drive letters available in Windows, I wrote the
following routine (following a suggestion from my genius work colleague):
<?php
$drive_letters = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z";
$drives = explode(" ", $drive_letters);
for ($idx = 0; $idx < count($drives); $idx++) {
$drive = $drives[$idx] . ":\\";
if (file_exists($drive) or is_dir($drive)) {
$acc_drives[] = $drive;
}
}
?>
Note that using both file_exists and is_dir isn't necessary. One or the other is fine. This
routine won't, however, recognise mapped network drives.
Also note that if PHP already provides this functionality in an existing function I didn't
discover it.
I can use the results in array acc_drives in the opendir function to get a directory listing of that
drive. This code isn't supposed to be perfect, just a guide to others trying to achieve the
same thing.
----
Manual Page -- http://www.php.net/manual/en/ref.filesystem.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47968
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47968&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47968&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47968&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47968&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47968&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47968&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47968&report=yes
Search -- http://master.php.net/manage/user-notes.php