Manipulating files and directories..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajd335
    New Member
    • Apr 2008
    • 123

    Manipulating files and directories..

    Hey all..I am trying to make as script , which can import one directory called IP , take all the text files one by one from that directory , and then can give me (using pregmatch or something ) Hostname from each file...
    Code is below..
    Code:
    <?php
     $dirname = "/home/ajd/IP";
    if($handle = opendir($dirname))
    { 
    while(false !== ($filename = readdir($handle))){
    echo $filename;
    $lines = file($filename);
    foreach($lines as $line_num)
    {
    print_r($lines);
    //$var = preg_match('/Host Name(.*)/',$matches);
    //print_r($matches);
     }
    }
    closedir($handle);
    } 
    ?>
    The above code gives me all the file names in the directory in which I am writing script (i.e home/ajd/data/ip.php
    It gives me list of files and directories in data directory...
    Please help out..
    Thanks
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, ajd.

    Try using glob() (http://php.net/glob).

    Comment

    Working...