Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7053857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:33:21+00:00 2026-05-28T03:33:21+00:00

I have a PHP 5.3.4 application running on Windows XP SP3 where I need

  • 0

I have a PHP 5.3.4 application running on Windows XP SP3 where I need to index the contents of a directory on a remote PC. The largest directory I’m indexing contains around 18,000 items.

This call would locate items like \\somepc.mycorp.com\foo\mydir\bar\zoo.zip.

// look in all the directories in \\somepc.mycorp.com\foo for directories containing a file \bar\zoo.zip
$item_list = GetFileList('\\\\somepc.mycorp.com\\foo', '\\bar\\zoo.zip');

It is implemented as:

function GetFileList($base_dir, $path_mask)
{
    $result= array();
    if ($handle = opendir($base_dir)) 
    {
        while (false !== ($entry = readdir($handle))) 
        {
            // only add items that match the mask we're looking for
            if ($entry != "." &&
                $entry != ".." && 
                file_exists($base_dir.'\\$entry\\$path_mask'))
            {
                array_push($result, $entry);
            }
        }

        closedir($handle);
    }
    return $result;
}

Unfortunately, for the largest directory structures, this operation can take over an hour. If I remove the filter and just insert every item seen in to the array, it will finish in a few seconds.

Is there a faster way to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:33:22+00:00Added an answer on May 28, 2026 at 3:33 am

    I hate to pull this card, but what you’re doing can be completed much faster using bash or even windows scripting – PHP is probably not the right tool for the job here. A system call (even from within PHP) to dir /s /b or find will get you a list of all files that exist, and then you can iterate over those strings with PHP much more quickly than checking to see if a file exists in every directory.

    I would do this in bash like this (because I’m lazy and don’t know the proper find syntax):

    find | grep '/bar/zoo.zip'
    

    I don’t know the appropriate windows shell command (because I have WinGnu32 grep installed on my machine), so I can’t help you there.

    Edit:

    I did a bit of fudging around and found the Windows equivalent of the above command:

    dir /s /b | find "/bar/zoo.zip"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We need to have our PHP application hosted on a 64 bit Windows OS
I have a PHP application and a need to generate a PDF with the
I have a Facebook application running on Amazon servers (windows data center + apache)
Windows 2008 R2 server running PHP 5.3. I have URL Rewrite for IIS working
I have a call center application running using php/javascript. When the operator is in
I have one big php application running on php 4 but I want to
I have an application (php) running with MySQL 5.5 (1 master and 1 slave)
I have a PHP application that displays a list of options to a user.
I have a Php application using stream_socket_client(), to get data through tcp from a
I have a PHP application that will on occasion have to handle URLs where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.