Jump to content

Determine if Folder


Recommended Posts

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.

 

Link to post
Share on other sites
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.

  • Like 1
Link to post
Share on other sites
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...

Link to post
Share on other sites
This thread is more than a year old.

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.