noon Posted August 14, 2007 Share Posted August 14, 2007 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 More sharing options...
noon Posted August 14, 2007 Author Share Posted August 14, 2007 For some reason I didnt think that while($files[$count] = readdir($dir)) would work... what a n00b Link to comment https://forums.phpfreaks.com/topic/64842-solved-readdir-logic/#findComment-323542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.