Jump to content

[SOLVED] readdir logic..


noon

Recommended Posts

Hi, I want to use readdir to get all the filenames from a particular directory.  more importantly, the number of files because I have created the files and know their naming convention.  I have the create function separate from what I am working on now which is why I do not just use the information I already have.  Inside my create function I return the directory name I created instead of, for instance an array of the filenames.  (now that I think of it... i could create an array with [0] the name of the directory and the rest of the array the filenames...)

 

Anyways, continuing on with my original thoughts.  If I have the following pseudo code:

 

while (readdir($dir))
{
  $files[$count] = readdir($dir)  // readdir would actually be the 2nd file now since I already advanced it in the if statement, no?
}

 

So I said ok i'll create a flag instead and set it to false once readdir returns false but I still can't capture the response from readdir without losing the file name.  Should I have a while loop once to increment a counter to determine how many files are in the directory and then have a for loop incrementing up until the counter to use readdir to capture the file names?

Link to comment
https://forums.phpfreaks.com/topic/64842-solved-readdir-logic/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.