Scandir Seems To Display Files I Have Deleted/Moved

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jbh
Forum Commoner
Posts: 89
Joined: Tue Dec 05, 2006 7:01 pm

Scandir Seems To Display Files I Have Deleted/Moved

Post by jbh »

Hey,

Does anybody know why the scandir function, when you print out the results of using this with a directory, doesn't show the true updated list of files? For instance, if I use

scandir($path) and then print out the files, everything *looks* normal

However, I have found that if I delete one file in that directory and re-print out the files using scandir, that file still appears in the array!
This works with a firefox browser re-boot, session logout etc. Does anybody know why that is? Is there a way around it or do I just have to use
other methods? (Which is fine, I found a way around it but I just cannot believe what I saw with this function)

Thanks for your time.

PS. For those who are curious, this is what I did

Code: Select all

 
$zipfile = scandir("/home/path/to/directory"); // just point this to a directory with some zip files
 
print_r($zipfile); // this displays the contents. 
 
 
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Scandir Seems To Display Files I Have Deleted/Moved

Post by pickle »

Are you retrieving the list of files, then deleting one file, then showing the list of files?

Also, please use [syntax=php][/syntax] when posting PHP - it makes it much easier to read.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Scandir Seems To Display Files I Have Deleted/Moved

Post by RobertGonzalez »

How are you confirming file deletes are taking place?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Scandir Seems To Display Files I Have Deleted/Moved

Post by Oren »

Like fstat(), the result might be from cache, check it out.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Scandir Seems To Display Files I Have Deleted/Moved

Post by pickle »

Oren wrote:Like fstat(), the result might be from cache, check it out.
I thought that too, but scandir() isn't in the list of functions the docs say are affected by caching.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Scandir Seems To Display Files I Have Deleted/Moved

Post by Oren »

I know - I checked too, that's why I said it *might*.
Post Reply