Skip to content

Commit

Permalink
Added compatible with WINDOWS deleting of folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Vano Devium committed Oct 7, 2019
1 parent af9f094 commit 8afcae4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/SkrubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeLn(' ');

// An array of directories that we're happy to remove.
$directories_to_remove = [ 'test', 'tests', 'fixture', 'fixtures', 'stub', 'stubs', 'docs', 'doc', 'examples',
'example', 'docker', 'other' ];
$directories_to_remove = [
'test', 'tests',
'fixture', 'fixtures',
'stub', 'stubs',
'doc', 'docs',
'example', 'examples',
'docker',
'other'
];


// Build a path to the vendor folder.
Expand All @@ -68,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$name = $path->getFileName();

// Is the given path a directory? and does it match the names we have?
if (($path->isDir() === true) && (in_array($name, $directories_to_remove)) && (substr_count($full_path, '/') === 4)) {
if (($path->isDir() === true) && (in_array($name, $directories_to_remove, true)) && (substr_count($full_path, '/') === 4)) {
// Is the directory the 4rd level deep?
//
// ie, vendor/somedude/somepackage/Tests
Expand Down Expand Up @@ -109,7 +116,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Perform the actual deletion of files if we're asked to.
if ($input->getOption('perform') === true) {
foreach ($directories_to_action as $directory) {
shell_exec('rm -rf '.$directory['path']);
if ('\\' === DIRECTORY_SEPARATOR) {
shell_exec('rd /S /Q '.$directory['path']);
} else {
shell_exec('rm -rf '.$directory['path']);
}
$output->writeLn('🗑 Deleting: '.$directory['path']. ' (saving '.$this->bytesToHumanReadable($directory['size']).')');

if (!file_exists($directory['path']) === true) {
Expand Down

0 comments on commit 8afcae4

Please sign in to comment.