sneskid Posted October 27, 2006 Share Posted October 27, 2006 I've read all the typical mumbo jumbo on directory scanning and counting content, but it seems like the more practical stuff is missing.1: The rewinddir function is nice... but is there a fast way to arbitrarily jump dir position? (like what fseek is to files)Would this somehow be possible with the resource context param? 2: Shouldn't the Count of contents in a directry be kept as a value by the system? Would save time otherwise wasted on iterating through.3: Hypothetically, if there are millions of files in a directory, are you screwed?Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/25363-dir-functions/ Share on other sites More sharing options...
ksteuber Posted October 28, 2006 Share Posted October 28, 2006 Here are the answers as far as I know them1) If any such function exists, I don't know of it. Just define one.[code]<?phpfunction dirseek($path,$num) {if (!($handle = opendir($path))) {echo "The path could not be opened";return;} else {$i=0;while (FALSE !== ($file = readdir($handle)) && $i < $num) { $i++; }closedir($handle);return $file;}}?>[/code]2) Whether or not this should be true hypothetically, it's not.3) No, you underestimate how fast a computer, especially a server can find files. Link to comment https://forums.phpfreaks.com/topic/25363-dir-functions/#findComment-115680 Share on other sites More sharing options...
sneskid Posted October 28, 2006 Author Share Posted October 28, 2006 my concern with the solution you presented was the needless memory usage it comes with (although it's better than scandir, according to this http://bugs.php.net/bug.php?id=31515)Thanks though.I'll have to devise some sort of indexing scheme or something. Link to comment https://forums.phpfreaks.com/topic/25363-dir-functions/#findComment-115701 Share on other sites More sharing options...
ksteuber Posted October 28, 2006 Share Posted October 28, 2006 Unless you are running these script on a pretty out of date server, or you are getting a ton of hits I don't think that you need to worry too much about that.Time the function; I would bet it takes less than a second. And afterwards, the memory no longer being used. Not a particularly heavy burden on any server. Link to comment https://forums.phpfreaks.com/topic/25363-dir-functions/#findComment-115710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.