Cleans a directory path by removing /. from the end.

@param string $dir_path
The path name to clean.

@return string
The clean path name.
436819
protected function cleanDirPath($dir_path) {
    // Remove annoying /. at the end. This is needed because the
    // DirectoryIterator adds that to the end of the dir name.
    $dir_path = rtrim($dir_path, '.');
    $dir_path = rtrim($dir_path, DIRECTORY_SEPARATOR);
    return $dir_path;
  }
349976
private function _cleanDirectory($path = '')
    {
        $resources = scandir($this->_base.$path);
        $resourceCount = count($resources);
        $links =
        $files = array();

        // Run through the directory contents
        foreach ($resources as $resource) {
            $absResource = $this->_base.$path.DIRECTORY_SEPARATOR.$resource;
            $origResource = SQUEEZR_DOCROOT.$path.DIRECTORY_SEPARATOR.$resource;

            // Ignore symbolic links to current and parent directory
            if (@is_dir($absResource) && (($resource == '.') || ($resource == '..'))) {
                --$resourceCount;
                continue;
            }

            // If it's a directory ...
            if (@is_dir($absResource)) {

                // Clean recursively and remove it alltogether in case it remains empty
                if (!@is_dir($origResource) || !$this->_cleanDirectory(ltrim($path.DIRECTORY_SEPARATOR.$resource,
                        DIRECTORY_SEPARATOR))
                ) {
                    @exec('rm -R '.escapeshellarg($absResource));
                    --$resourceCount;
                }

                // Else if it's a symbolic link: register it
            } elseif (@is_link($absResource)) {
                $links[] = $resource;

                // Else if it's a regular file: register it
            } elseif (@is_file($absResource)) {
                $files[] = $resource;

                // Else: No idea ... delete it!
            } else {
                if (@unlink($absResource)) {
                    --$resourceCount;
                }
            }
        }

        // Check & clean regular files
        foreach ($files as $file) {
            $absResource = $this->_base.$path.DIRECTORY_SEPARATOR.$file;

            // Proceed based on file extension
            switch (strtolower(pathinfo($file, PATHINFO_EXTENSION))) {

                // CSS file
                case 'css':

                    // If it's a breakpoint CSS file
                    if (preg_match("%^(.+)\-\d+\.css$%i", $file, $breakpointCssFile)) {
                        $origResource = SQUEEZR_DOCROOT.$path.DIRECTORY_SEPARATOR.$breakpointCssFile[1].'.css';

                        // Else: No idea ... delete it!
                    } else {
                        if (@unlink($absResource)) {
                            --$resourceCount;
                        }
                        continue 2;
                    }
                    break;

                // PHP cache file
                case 'php':

                    // If it's a PHP cache file
                    if (preg_match("%^(.+)\-squeezr\.css\.php$%i", $file, $phpCacheFile)) {
                        $origResource = SQUEEZR_DOCROOT.$path.DIRECTORY_SEPARATOR.$phpCacheFile[1].'.css';

                        // Else: No idea ... delete it!
                    } else {
                        if (@unlink($absResource)) {
                            --$resourceCount;
                        }
                        continue 2;
                    }
                    break;

                // Image files
                case 'png':
                case 'jpg':
                case 'jpeg':
                case 'gif':
                    $origResource = SQUEEZR_DOCROOT.$path.DIRECTORY_SEPARATOR.$file;
                    break;

                // Other extensions: Ignore
                default:
                    continue 2;
                    break;
            }

            // Remove the cache file if the original file doesn't exist anymore or is younger
            if (!@is_file($origResource) || (@filemtime($origResource) > @filemtime($absResource))) {
                if (@unlink($absResource)) {
                    --$resourceCount;
                }
            }
        }

        // Check & clean symbolic links
        foreach ($links as $link) {
            $absResource = $this->_base.$path.DIRECTORY_SEPARATOR.$link;
            $origResource = @readlink($absResource);

            // Delete the symbolic link if the original file doesn't exist anymore
            if ((!$origResource || !@is_file($origResource)) && @unlink($absResource)) {
                --$resourceCount;
            }
        }

        return $resourceCount;
    }
885525
public static function clean_up_path($path)
    {

        if (empty($path)) return '';
        if (strpos($path, '\\') !== false) {
            return str_replace("\\\\", "\\", $path);
        } else {
            return str_replace("//", "/", $path);
        }
    }
810852
private function cleanPath(string $dest)
  {
    $dest = substr($dest, 0, 1) == DIRECTORY_SEPARATOR ? substr($dest, 1) : $dest;
    return $dest[strlen($dest) - 1] == '/' ? substr($dest, 0, strlen($dest) - 1) : $dest;
  }
25126
static function dirpath( $filepath )
    {
        $filepath = eZDir::cleanPath( $filepath, self::SEPARATOR_UNIX );
        $dirPosition = strrpos( $filepath, '/' );
        if ( $dirPosition !== false )
            return substr( $filepath, 0, $dirPosition );
        return $filepath;
    }
484839
private static function rrmdir($path)
    {
        $path .= '/';

        foreach (array_diff(scandir($path), array('..', '.')) as $file) {
            $current = $path . $file;

            if (is_dir($current)) {
                if (self::rrmdir($current) === false) {
                    return false;
                }
            } elseif (unlink($current) === false) {
                return false;
            }
        }

        return rmdir($path);
    }
220344
protected function sanitizePath($path)
    {
        $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);

        $path = preg_replace('/'.preg_quote('./', '/').'/', '', $path, 1);
        $path = trim($path, '/');

        return $path;
    }
390279
static function cleanupEmptyDirectories( $dir )
    {
        $dir = self::cleanPath( $dir, self::SEPARATOR_UNIX );
        $dirElements = explode( '/', $dir );
        if ( count( $dirElements ) == 0 )
            return true;
        $currentDir = $dirElements[0];
        $result = true;
        if ( !file_exists( $currentDir ) and $currentDir != "" )
            $result = self::doMkdir( $currentDir, self::directoryPermission() );
        if ( !$result )
            return false;

        for ( $i = count( $dirElements ); $i > 0; --$i )
        {
            $dirpath = implode( '/', array_slice( $dirElements, 0, $i ) );
            if ( file_exists( $dirpath ) and
                 is_dir( $dirpath ) )
            {
                $rmdirStatus = @rmdir( $dirpath );
                if ( !$rmdirStatus )
                    return true;
            }
        }
        return true;
    }
66962
def _clean_directory(self, name):
        """"""
        if not os.path.exists(name):
            return
        self.announce(
            "removing directory '{}' and all its contents".format(name)
        )
        if not self.dry_run:
            rmtree(name, True)
551636
public static function fixDirectorySeparator(string $path, $useCleanPrefix = false) : string
    {
        /**
         * Trimming path string
         */
        if (($path = trim($path)) == '') {
            return $path;
        }

        $path = preg_replace('`(\/|\\\)+`', DIRECTORY_SEPARATOR, $path);
        if ($useCleanPrefix) {
            $path = DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR);
        }

        return $path;
    }
911386
public static function cleanupEmptyDirectories( $path )
    {
        $dirpath = eZDir::dirpath( $path );

        eZDebugSetting::writeDebug( 'kernel-clustering', "eZClusterFileHandler::cleanupEmptyDirectories( '{$dirpath}' )" );

        if ( is_dir( $dirpath ) )
        {
            eZDir::cleanupEmptyDirectories( $dirpath );
        }
    }
222218
def remove_empty_dir(path):
    
    try:
        if not os.path.isdir(path):
            return

        files = os.listdir(path)

        # if folder empty, delete it
        if len(files) == 0:
            os.rmdir(path)

        # remove empty subdirectory
        elif len(files) > 0:
            for f in files:
                abspath = os.path.join(path, f)
                if os.path.isdir(abspath):
                    remove_empty_dir(abspath)
    except OSError as e:
        if e.errno == errno.ENOTEMPTY:
            pass
66737
public static function emptyDirRecursive($dirPath)
    {
        foreach (
            new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($dirPath, FilesystemIterator::SKIP_DOTS),
                RecursiveIteratorIterator::CHILD_FIRST
            ) as $path
        ) {
            if ($path->isFile()) {
                unlink($path->getPathname());
            } else {
                rmdir($path->getPathname());
            }
        }
    }
700984
public static String cleanPath(String path) {
        if (path.endsWith(SEPARATOR)) {
            path = path.replaceAll(SEPARATOR + "+$", "");
        }
        if (path.startsWith(SEPARATOR)) {
            path = path.replaceAll("^" + SEPARATOR + "+", "");
        }
        return path.replaceAll("/+", SEPARATOR);
    }
354348
public static function delete($file_path)
    {
        $result = false;
        if (self::fileExists($file_path)) {
            $result = unlink($file_path);
        }
        return $result;
    }
1374212
public static function delete($path)
    {
        $files = self::getContent($path);
        foreach ($files as $file) {
            if (is_dir($path.DIRECTORY_SEPARATOR.$file)) {
                self::delete($path.DIRECTORY_SEPARATOR.$file);
            } else {
                @unlink($path.DIRECTORY_SEPARATOR.$file);
            }
        }

        return @rmdir($path);
    }
828292
function removeDir(dirPath, cleanOnly) {
  var files;

  try {
    files = fs.readdirSync(dirPath);
  } catch(e) {
    return;
  }

  if (files.length > 0) {
    for (var i = 0; i < files.length; i++) {
      var filePath = path.join(dirPath, files[i]);
      if (fs.statSync(filePath).isFile())
        fs.unlinkSync(filePath);
      else
        rmDir(filePath);
    }
  }

  !cleanOnly && fs.rmdirSync(dirPath);
}