SaranacLake Posted December 15, 2019 Share Posted December 15, 2019 Hello. I have code that goes into a directory and reads all filenames. I could use some help tweaking my code - using a regex - to prevent including any folders. Here is what I have so far... while(($file = readdir($handle)) != FALSE){ if($file != '.' && $file != '.' && $file != '..' && $file != '_small' && $file != '_med' && $file != preg_match("#^[^\.].*$#, $file)){ $photoFiles[] = $file; } I couldn't figure out a working regex to prevent folders/subfolders so I had to hard-code the above folders which is of course limiting! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/309685-determine-if-folder/ Share on other sites More sharing options...
Zane Posted December 15, 2019 Share Posted December 15, 2019 PHP has a handy function for this called: is_dir() 1 Quote Link to comment https://forums.phpfreaks.com/topic/309685-determine-if-folder/#findComment-1572523 Share on other sites More sharing options...
Psycho Posted December 17, 2019 Share Posted December 17, 2019 On 12/14/2019 at 10:36 PM, Zane said: PHP has a handy function for this called: is_dir() What he said. There is no way to positively determine if an element is a folder or file by the name. A files doesn't have to have an extension. It's kind of difficult to create a file w/o an extentiosn, but not impossible. But, the function is_dir() [or the converse is_file()] will positively make that distinction. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309685-determine-if-folder/#findComment-1572599 Share on other sites More sharing options...
SaranacLake Posted December 18, 2019 Author Share Posted December 18, 2019 22 hours ago, Psycho said: What he said. There is no way to positively determine if an element is a folder or file by the name. A files doesn't have to have an extension. It's kind of difficult to create a file w/o an extentiosn, but not impossible. But, the function is_dir() [or the converse is_file()] will positively make that distinction. Working on fixing some other issues but will circle back to this... Quote Link to comment https://forums.phpfreaks.com/topic/309685-determine-if-folder/#findComment-1572657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.