Skip to content
This repository was archived by the owner on May 9, 2021. It is now read-only.

.DS_Store removal from folders #22

@orukaz

Description

@orukaz

You have to make script to remove .DS_Store from directories. Here is my Laravel command that I included in my dev projects:

RemoveDSStore.php:

<?php

namespace RaidoOrumets\Base\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Process\Process;

class RemoveDSStore extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'dsstore:remove {path? : Path (default: base_path}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Removes all the .DS_Store files from project';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $path = $this->argument('path') ?? base_path();
        $this->line($path);
        $process = Process::fromShellCommandline("find ". $path ." -name '*.DS_Store' -exec rm -r {} \;");

        // Start the process.
        $process->run();

        // Determine if the process failed.
        if (!$process->isSuccessful()) {
            // Handle process failure.
            $this->error('<fg=black;bg=red> ERROR </><bg=default> </> <fg=yellow;bg=red>.DS_Store</> cannot be removed!');
        } else {
            $this->info('<fg=black;bg=green> DONE </> All the <fg=yellow>.DS_store</> files are removed.');
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions