Results 1 to 7 of 7

Thread: [RESOLVED] Search a file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Resolved [RESOLVED] Search a file

    Hi,

    I want to search a file's directory - so, if I search the file 0466-01-03.sldprt, PHP returns the path where the file is. All files are unique and on the server's filesystem (intranet).

    Is that possible?

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Search a file

    Try something like this, you have to read all the files in the directory and match them.

    PHP Code:
    <?php
    if ($handle opendir('.')) {
       while (
    false !== ($file readdir($handle))) {
           if (
    $file != "." && $file != "..") {
               if(
    $file == "0466-01-03.sldprt"){ //match file
                   //do stuff with the file here
               
    }
           }
       }
       
    closedir($handle);
    }
    ?>
    The only other method i can think of would be to use exec() and execute "ls" or "dir" with the filename. and parse the results.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Search a file

    Does that also work if the files are saved in other directories, eg. ../01/03? Engineers aren't predictable when it's about saving the files :P

  4. #4
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Search a file

    jsut change the parameter passed to opendir(). You can check to see if the item return is a file or a directory using is_file() or is_dir()

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Search a file

    You could make a recursive search function, if any result is a directory you call the function again with that base path.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Search a file

    It won't work...it just prints a blank screen

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Search a file

    Oh, it's case sensitive

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width