Page 1 of 1

Scandir Seems To Display Files I Have Deleted/Moved

Posted: Fri Jul 18, 2008 1:54 pm
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. 
 
 

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

Posted: Fri Jul 18, 2008 5:12 pm
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.

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

Posted: Fri Jul 18, 2008 7:46 pm
by RobertGonzalez
How are you confirming file deletes are taking place?

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

Posted: Sat Jul 19, 2008 3:11 am
by Oren
Like fstat(), the result might be from cache, check it out.

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

Posted: Mon Jul 21, 2008 10:47 am
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.

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

Posted: Mon Jul 21, 2008 12:52 pm
by Oren
I know - I checked too, that's why I said it *might*.