Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More useful file commands #26

Closed
schwern opened this issue Jun 7, 2009 · 8 comments
Closed

More useful file commands #26

schwern opened this issue Jun 7, 2009 · 8 comments

Comments

@schwern
Copy link
Contributor

schwern commented Jun 7, 2009

touch

recursive rm

mv and cp allowing multiple source files to a directory

mkdir -p

Crib from ExtUtils::Command and Shell::Command.

@cowens
Copy link
Contributor

cowens commented Jun 21, 2009

Is this too UNIX centric?

Recursive rm and mkdir -p already exist in File::Path as remove_tree and mkpath respectively. Multiple file mv and copy should be easy: move and copy from File::Copy combined with a for loop.

sub mv {
    my $dir = pop;
    croak "not enough args" unless @_;
    for my $file (@_) {
        move $file, $dir
            or croak "could not move '$file' to '$dir': $!;
    }
    return 1;
}

touch is implemented by Touch

@schwern
Copy link
Contributor Author

schwern commented Jun 21, 2009

The names are Unixy, but the need for the functionality is not. make_path() and remove_tree() are better. Not sure what to do about mv and cp and touch.

@cowens
Copy link
Contributor

cowens commented Jun 23, 2009

hmm, move_file/copy_file isn't good enough because you can move/copy a directory. And I don't like move or copy because they are general verbs. Naming them Fred and Barney isn't any good either. Must think some more.

@schwern
Copy link
Contributor Author

schwern commented Jan 25, 2010

Rather than making these functions, make them methods on file/dir objects. In particular, Path::Extended does a lot of this.

@kentfredric
Copy link

The following syntax looks reasonable to me:

dir("/some/dir/")->copy_to("/some/other/dir")  # produces /some/other/dir 
dir("/some/dir/")->copy_to("/some/other/dir")  # error, exists
dir("/some/dir/")->copy_to("/some/other/dir", { replace  => 1 })  # same as if you'd rm'd the target first
dir("/some/dir/")->copy_to("/some/other/dir", { merge  => 1 })  # tries to  recursively inject things.

dir("/some/dir/")->copy_into("/some/other/dir") # produces /some/other/dir/dir 
dir("/some/dir/")->copy_to("/some/other/file")   # error
dir("/some/dir/")->copy_into("/some/other/file")  # error

I'm probably trying too hard to be smart with that auto-remove/auto-merge thing.

@kentfredric
Copy link

doing that syntax with a list of things is probably the harder option, but I don't see why its neeed:

for ( @dirs ){ 
   dir($_)->copy_to( $target );
}

@dhorne
Copy link

dhorne commented Feb 13, 2013

How about Path::Tiny?

@schwern
Copy link
Contributor Author

schwern commented Jul 23, 2014

Path::Tiny covers touch, recursive rm (remove_tree()) and mkdir -p (mkpath).

Since this issue speculative, and much of that speculation and much much more is done by incorporating Path::Tiny, I'm going to close it. Concrete requests can be opened as separate issues.

@schwern schwern closed this as completed Jul 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants