473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Weird DirectoryIterator behaviour

guillermobytes
Hello,

can someone make light on this please :

i have a path to a dir:
Expand|Select|Wrap|Line Numbers
  1. $path = "/var/www/Tests";
  2. echo $path;
the output is :
Expand|Select|Wrap|Line Numbers
  1. /var/www/Tests
when i create a new DirectoryIterator like this :
Expand|Select|Wrap|Line Numbers
  1. $dirIt = new DirectoryIterator($path);
and ask php if it is a directory, it says its not!
Expand|Select|Wrap|Line Numbers
  1. if (!$dirIt->isDir()) {
  2.     echo "This is not a directory!";
  3. }
the output is :
Expand|Select|Wrap|Line Numbers
  1. This is not a directory!
and
Expand|Select|Wrap|Line Numbers
  1. print_r($dirIt);
output is a FILE!!
Expand|Select|Wrap|Line Numbers
  1. DirectoryIterator Object
  2. (
  3.     [pathName:SplFileInfo:private] => /var/www/Tests/enginecartelmania.php
  4.     [fileName:SplFileInfo:private] => enginecartelmania.php
  5.     [glob:DirectoryIterator:private] => 
  6.     [subPathName:RecursiveDirectoryIterator:private] => 
  7. )
can someone make sense to this?

thanks for your help
Jul 10 '11 #1
1 1498
Sorry, I was very tired... The answer is that DirectoryIterator iterates through the directory contents. So when i ask if the current element in DirectoryIterator is a directory, except when the directory iterator is pointing at the . and .. directories, the answer will allways be no!
The right way to do this is to call is_dir($path)
sorry for stupid post
Jul 11 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: gRabbi | last post by:
Hello Since some time i`m trying to work with java using Eclipse tool. On one of computers i`ve installed Eclipse i have some weird thing. No matter what kind of project i create (applet,form...
3
by: Samuel Caparros | last post by:
Hi group, I have an app where I use a class defined by myself. I've been using it normally until a few days ago. Every time I run a simple assignment... Dim LocalObjectOfMyClass as New MyClass...
8
by: Deano | last post by:
Here's the code; Private Sub txtTeachName_LostFocus() If IsNull(Me.txtName) Then 'line A Forms!frmMainform!frmSubform.Locked = True GoTo Exit_txtName Else 'line B...
1
by: Pankaj | last post by:
Hi All, I use a Hashtable in my program to keep unique items...at one instance I need to repopulate this hashtable through a loop. when starting repopulation hashtable.count() returns ZERO...
3
by: Val | last post by:
In vc7 (studio 2002), when I try to debug the first "if" statement, the IDE jumps to the next valid line and evaluates it even if the if-statement is false. What is going on? if(...
1
by: fd123456 | last post by:
The TextBoxes in ASP have a weird behaviour when it comes to handling carriage returns. You can try this : Create a Webform. On it, place a textbox, set it's TextMode property to MultiLine....
1
by: hecsan07 | last post by:
I am trying to perform site login using values from a cookie, but for some weird reason the cookie is being destroyed after the browser window is closed. I checked the browser settings for the...
2
by: Jethro | last post by:
Having upgraded my VB6 project .... This doesn't work dim i as integer For i = 0 to 8 MyRecordset.Fields(i).Value = "Test" <---------- Error thrown here "item or variable not found in...
4
by: Kevin O'Donovan | last post by:
Hi, Is anyone else experiencing this, or better yet, have a fix for it: We have VS.Net 2003 from the MSDN Universal subscription installed on 3 workstations. We have about 10 or so projects...
2
by: greg | last post by:
In my quest to eliminate C compiler warnings from Pyrex output, I've discovered some utterly bizarre behaviour from gcc 3.3. The following code: void g(struct foo *x) { } void f(void) {
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.