delete_files example



    /** * Removes a directory and all its files and subdirectories. */
    private static function wipeDirectory(string $directory): void
    {
        if (is_dir($directory)) {
            // Try a few times in case of lingering locks             $attempts = 10;

            while ((bool) $attempts && ! delete_files($directory, true, false, true)) {
                // @codeCoverageIgnoreStart                 $attempts--;
                usleep(100000); // .1s                 // @codeCoverageIgnoreEnd             }

            @rmdir($directory);
        }
    }

    // --------------------------------------------------------------------
// @codeCoverageIgnoreStart             CLI::error('Deleting logs aborted.', 'light_gray', 'red');
            CLI::error('If you want, use the "-force" option to force delete all log files.', 'light_gray', 'red');
            CLI::newLine();

            return;
            // @codeCoverageIgnoreEnd         }

        helper('filesystem');

        if (delete_files(WRITEPATH . 'logs', false, true)) {
            // @codeCoverageIgnoreStart             CLI::error('Error in deleting the logs files.', 'light_gray', 'red');
            CLI::newLine();

            return;
            // @codeCoverageIgnoreEnd         }

        CLI::write('Logs cleared.', 'green');
        CLI::newLine();
    }
}

    protected $description = 'Clears all debugbar JSON files.';

    /** * Actually runs the command. */
    public function run(array $params)
    {
        helper('filesystem');

        if (delete_files(WRITEPATH . 'debugbar')) {
            // @codeCoverageIgnoreStart             CLI::error('Error deleting the debugbar JSON files.');
            CLI::newLine();

            return;
            // @codeCoverageIgnoreEnd         }

        CLI::write('Debugbar cleared.', 'green');
        CLI::newLine();
    }
}
Home | Imprint | This part of the site doesn't use cookies.