Re: File Ext

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This will work, with several caveats since the purpose is not known.......

<?php
 $dir = dir("c:/");
 while($filename=$dir->read())
 {
  if (!is_dir($filename))
  {
   clearstatcache();
   $extension = substr($filename,-4);
   $realext = strstr($extension, ".");
   if ($realext <> "")
   {
    echo $realext."<br>\n";
   }
  }
 }
 $dir->close();
?>

Output for me looked like this:
.BAT
.ini
.SYS
.sys
.SYS
.SYS
.cnf
.COM

One of the exceptions is that the is_dir function doesn't really seem to
work on windows/IIS.  Since this is the only test environment I have, I can
only assume that it does work ok with a linux-based webserver or it wouldn't
be in there. In fact, if I put in is_file() instead of !is_dir, it returns
nothing at all.  Anyway, that takes a list of all files and directory names
in the given directory (c:/ - yes it has to be a / not a \ - in my example),
checks to see if it's a directory or a file (theoretically...), then grabs
the last 4 characters that start with a ".", tosses them onto the screen.
Replace the last echo with whatever manipulation you're going for.  The
things this will include that it shouldn't:  directories with a 3-character
extension.  Things it won't include that you might need:  files with a
4-character-or-more or a 2-character-or-less extension.  It only grabs
3-character extensions.  From here, though, I think you can modify it to do
whatever it is you need done.

(V)

----- Original Message ----- 
From: "Dean Hayes" <wizard_guy@hotmail.com>
> Hey,
>
> I need to be able to find out what the file ext is on all files within the
> dir i am reading. I am searched the php manual and i can not find anything
> that does this does anyone know of a way i can and print it out.

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux