Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.