Does this method for getting drives work for anyone?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ImOk

    Does this method for getting drives work for anyone?

    WHen I run this under Windows I get the Count of drives but then I get
    an error message on the Reset() when I try to enumerate. Does this work
    for anyone?

    $fs = new COM("Scripting. FileSystemObjec t");
    $drives = $fs->Drives;
    echo $drives->Count;
    $drives->Reset();
    while($drive = $drives->Next()) {
    echo $drive->VolumeName;
    }


    2PHP Stack trace: PHP 1. {main}() C:\PHP5Apps\PHP X\fso.php:0 PHP Fatal
    error: Call to undefined method variant::Reset( ) in
    C:\PHP5Apps\PHP X\fso.php on line 5

  • Chung Leong

    #2
    Re: Does this method for getting drives work for anyone?


    ImOk wrote:[color=blue]
    > WHen I run this under Windows I get the Count of drives but then I get
    > an error message on the Reset() when I try to enumerate. Does this work
    > for anyone?
    >
    > $fs = new COM("Scripting. FileSystemObjec t");
    > $drives = $fs->Drives;
    > echo $drives->Count;
    > $drives->Reset();
    > while($drive = $drives->Next()) {
    > echo $drive->VolumeName;
    > }
    >
    >
    > 2PHP Stack trace: PHP 1. {main}() C:\PHP5Apps\PHP X\fso.php:0 PHP Fatal
    > error: Call to undefined method variant::Reset( ) in
    > C:\PHP5Apps\PHP X\fso.php on line 5[/color]

    I think it was I who posted that fragment. The code only works in PHP
    4. In PHP 5, you just enumerate $drives as though it's a regular array.
    Hence:

    $fs = new COM("Scripting. FileSystemObjec t");
    $drives = $fs->Drives;
    foreach($drives as $drive) {
    echo $drive->DriveLetter;
    }

    Comment

    • ImOk

      #3
      Re: Does this method for getting drives work for anyone?


      Chung Leong wrote:[color=blue]
      > ImOk wrote:[color=green]
      > > WHen I run this under Windows I get the Count of drives but then I get
      > > an error message on the Reset() when I try to enumerate. Does this work
      > > for anyone?
      > >
      > > $fs = new COM("Scripting. FileSystemObjec t");
      > > $drives = $fs->Drives;
      > > echo $drives->Count;
      > > $drives->Reset();
      > > while($drive = $drives->Next()) {
      > > echo $drive->VolumeName;
      > > }
      > >
      > >
      > > 2PHP Stack trace: PHP 1. {main}() C:\PHP5Apps\PHP X\fso.php:0 PHP Fatal
      > > error: Call to undefined method variant::Reset( ) in
      > > C:\PHP5Apps\PHP X\fso.php on line 5[/color]
      >
      > I think it was I who posted that fragment. The code only works in PHP
      > 4. In PHP 5, you just enumerate $drives as though it's a regular array.
      > Hence:
      >
      > $fs = new COM("Scripting. FileSystemObjec t");
      > $drives = $fs->Drives;
      > foreach($drives as $drive) {
      > echo $drive->DriveLetter;
      > }[/color]

      I had tried the enumeration later and it worked fine. But thanks anyway.

      Comment

      Working...