Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. System.php

function System::rm

The rm command for removing files. Supports multiple files and dirs and also recursive deletes

@static @access public

Parameters

string $args the arguments for rm:

Return value

mixed PEAR_Error or true for success

1 call to System::rm()
System::_removeTmpFiles in vendor/pear/pear-core-minimal/src/System.php
Remove temporary files created my mkTemp. This function is executed at script shutdown time

File

vendor/pear/pear-core-minimal/src/System.php, line 210

Class

System
System offers cross platform compatible system functions

Code

public static function rm($args) {
    $opts = System::_parseArgs($args, 'rf');
    // "f" does nothing but I like it :-)
    if (PEAR::isError($opts)) {
        return System::raiseError($opts);
    }
    foreach ($opts[0] as $opt) {
        if ($opt[0] == 'r') {
            $do_recursive = true;
        }
    }
    $ret = true;
    if (isset($do_recursive)) {
        $struct = System::_multipleToStruct($opts[1]);
        foreach ($struct['files'] as $file) {
            if (!@unlink($file)) {
                $ret = false;
            }
        }
        rsort($struct['dirs']);
        foreach ($struct['dirs'] as $dir) {
            if (!@rmdir($dir)) {
                $ret = false;
            }
        }
    }
    else {
        foreach ($opts[1] as $file) {
            $delete = is_dir($file) ? 'rmdir' : 'unlink';
            if (!@$delete($file)) {
                $ret = false;
            }
        }
    }
    return $ret;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal