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

  • SEARCH
  • Home
  • 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 6891505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:25:07+00:00 2026-05-27T06:25:07+00:00

is_dir() according to the php manual returns true if passed a string that refers

  • 0

is_dir() according to the php manual returns true if passed a string that refers to a folder.
It’s returning false — despite being passed an array of valid folder names — this is probably something simple but I’m beating myself up over not finding it.

Here is the code:

define('TEST_SUBFOLDERS_FILES_PATH', 'C:/xampp/htdocs/theProj/mainSubdir/');

$currentFolder = ' ';
$rootOfmainSubdir = TEST_SUBFOLDERS_FILES_PATH';
$theArrayOfDirsAndFilesInmainSubdir;

// fill an array that contains all files and folders under the /mainSubdir folder
// using php's 'scandir()'
if( ($theArrayOfDirsAndFilesInmainSubdir = scandir($rootOfmainSubdir )) != FALSE )
{
  $numArrayEntries = count($theArrayOfDirsAndFilesInmainSubdir);
  echo "<br><br>The number of folders/files found is:  " . $numArrayEntries;


  // now do the triage on subfolders under /mainSubdir  versus files
  for($i = 0; $i < $numArrayEntries; $i++)
  {
    echo "<br><br>Current array element is:  " 
            . $theArrayOfDirsAndFilesInmainSubdir[$i]
            . "  and is_dir() on this element returns --> "
            . var_dump( is_dir($theArrayOfDirsAndFilesInmainSubdir[$i]) );  
    // rest of code

Here is what I see on the output for almost all the folders:

Current array element is: testFolderN and is_dir() on this element returns -->

boolean false

OR I see:

Current array element is: . and is_dir() on this element returns -->

boolean true

AND:

Current array element is: .. and is_dir() on this element returns -->

boolean true

I’m missing something really dumb here but sheesh. It seems that is_dir() is correctly returning TRUE only for the current folder “.” and the parent folder “..”

If there is a nuance I’m missing in the use of is_dir() I’m not seeing it.

Help is appreciated — all I’m going to do in the code is to make a list of the current subfolders under the TEST_SUBFOLDERS_FILES_PATH if I can get is_dir() to return TRUE not only for “.” and “..” but also the other ‘testFolderN’ subfolders.

By the way — there is a total of 5 subfolders, and one file in the directory, so the display of the count above is:

The number of folders/files found is: 8
  • 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-27T06:25:08+00:00Added an answer on May 27, 2026 at 6:25 am

    You scan the $rootOfmainSubdir, but you test for is_dir()ness in your current directory. You can either prepend the root and directory separator before checking, or chdir() in there. Note, that your current directory also has . and .. entries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a script that will: 1- locate folder store on a
EDIT2: model.hasChildren(parentIndex) returns True , but model.rowCount(parentIndex) returns 0 . Is QFileSystemModel just fubar
According to this manual I tried to set the proxy extension. In my_prof_dir/extensions there
I'm trying to use tmpfile() but is returning false for me. I can't use
I'm unsure of how to alter my php.ini file according to the instructions on
I'm trying to install dajax / dajaxice according to their documentation, which suggests that
According to section 3.7.1 of the Bash manual, variable assignments at the beginning of
If I have example.com/dir and dir is basically a folder in the example.com server,
Here is one method that monkey patched the Dir[] method from autotest class Dir
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's

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.