Title: WP_Filesystem_Base::find_folder
Published: April 25, 2014
Last modified: April 28, 2025

---

# WP_Filesystem_Base::find_folder( string $folder ): string|false

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#wp--skip-link--target)

Locates a folder on the remote filesystem.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#description)󠁿

Assumes that on Windows systems, Stripping off the Drive letter is OK Sanitizes \
to / in Windows filepaths.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#parameters)󠁿

 `$folder`stringrequired

the folder to locate.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#return)󠁿

 string|false The location of the remote path, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#source)󠁿

    ```php
    public function find_folder( $folder ) {
    	if ( isset( $this->cache[ $folder ] ) ) {
    		return $this->cache[ $folder ];
    	}

    	if ( stripos( $this->method, 'ftp' ) !== false ) {
    		$constant_overrides = array(
    			'FTP_BASE'        => ABSPATH,
    			'FTP_CONTENT_DIR' => WP_CONTENT_DIR,
    			'FTP_PLUGIN_DIR'  => WP_PLUGIN_DIR,
    			'FTP_LANG_DIR'    => WP_LANG_DIR,
    		);

    		// Direct matches ( folder = CONSTANT/ ).
    		foreach ( $constant_overrides as $constant => $dir ) {
    			if ( ! defined( $constant ) ) {
    				continue;
    			}

    			if ( $folder === $dir ) {
    				return trailingslashit( constant( $constant ) );
    			}
    		}

    		// Prefix matches ( folder = CONSTANT/subdir ),
    		foreach ( $constant_overrides as $constant => $dir ) {
    			if ( ! defined( $constant ) ) {
    				continue;
    			}

    			if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir.
    				$potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder );
    				$potential_folder = trailingslashit( $potential_folder );

    				if ( $this->is_dir( $potential_folder ) ) {
    					$this->cache[ $folder ] = $potential_folder;

    					return $potential_folder;
    				}
    			}
    		}
    	} elseif ( 'direct' === $this->method ) {
    		$folder = str_replace( '\\', '/', $folder ); // Windows path sanitization.

    		return trailingslashit( $folder );
    	}

    	$folder = preg_replace( '|^([a-z]{1}):|i', '', $folder ); // Strip out Windows drive letter if it's there.
    	$folder = str_replace( '\\', '/', $folder ); // Windows path sanitization.

    	if ( isset( $this->cache[ $folder ] ) ) {
    		return $this->cache[ $folder ];
    	}

    	if ( $this->exists( $folder ) ) { // Folder exists at that absolute path.
    		$folder                 = trailingslashit( $folder );
    		$this->cache[ $folder ] = $folder;

    		return $folder;
    	}

    	$return = $this->search_for_folder( $folder );

    	if ( $return ) {
    		$this->cache[ $folder ] = $return;
    	}

    	return $return;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-base.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/class-wp-filesystem-base.php#L177)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-wp-filesystem-base.php#L177-L245)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Filesystem_Base::is_dir()](https://developer.wordpress.org/reference/classes/wp_filesystem_base/is_dir/)`wp-admin/includes/class-wp-filesystem-base.php` |

Checks if resource is a directory.

  | 
| [WP_Filesystem_Base::exists()](https://developer.wordpress.org/reference/classes/wp_filesystem_base/exists/)`wp-admin/includes/class-wp-filesystem-base.php` |

Checks if a file or directory exists.

  | 
| [WP_Filesystem_Base::search_for_folder()](https://developer.wordpress.org/reference/classes/wp_filesystem_base/search_for_folder/)`wp-admin/includes/class-wp-filesystem-base.php` |

Locates a folder on the remote filesystem.

  | 
| [trailingslashit()](https://developer.wordpress.org/reference/functions/trailingslashit/)`wp-includes/formatting.php` |

Appends a trailing slash.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#)

| Used by | Description | 
| [WP_Filesystem_Base::abspath()](https://developer.wordpress.org/reference/classes/wp_filesystem_base/abspath/)`wp-admin/includes/class-wp-filesystem-base.php` |

Returns the path on the remote filesystem of ABSPATH.

  | 
| [WP_Filesystem_Base::wp_content_dir()](https://developer.wordpress.org/reference/classes/wp_filesystem_base/wp_content_dir/)`wp-admin/includes/class-wp-filesystem-base.php` |

Returns the path on the remote filesystem of WP_CONTENT_DIR.

  | 
| [WP_Filesystem_Base::wp_plugins_dir()](https://developer.wordpress.org/reference/classes/wp_filesystem_base/wp_plugins_dir/)`wp-admin/includes/class-wp-filesystem-base.php` |

Returns the path on the remote filesystem of WP_PLUGIN_DIR.

  | 
| [WP_Filesystem_Base::wp_themes_dir()](https://developer.wordpress.org/reference/classes/wp_filesystem_base/wp_themes_dir/)`wp-admin/includes/class-wp-filesystem-base.php` |

Returns the path on the remote filesystem of the Themes Directory.

  | 
| [WP_Filesystem_Base::wp_lang_dir()](https://developer.wordpress.org/reference/classes/wp_filesystem_base/wp_lang_dir/)`wp-admin/includes/class-wp-filesystem-base.php` |

Returns the path on the remote filesystem of WP_LANG_DIR.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_base/find_folder/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_filesystem_base%2Ffind_folder%2F)
before being able to contribute a note or feedback.