Skip to content

Instantly share code, notes, and snippets.

@wryk
Last active October 3, 2017 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wryk/05a0edf384261b3bb1fa39417c61b73d to your computer and use it in GitHub Desktop.
Save wryk/05a0edf384261b3bb1fa39417c61b73d to your computer and use it in GitHub Desktop.
use Digest::SHA256::Native;
multi sub MAIN(Cool $input = '.', Bool :$recursive = False, Bool :$apply = False) {
for find-files($input, recursive => $recursive) -> $current {
my $next = $current.dirname.IO.add(sha256-hex(($current.slurp(:bin))) ~ '.' ~ $current.extension);
say $current.basename ~ ' => ' ~ $next.basename;
if ($apply && !($current.basename eq $next.basename)) {
$current.rename($next);
}
}
}
sub find-files (Cool $directory = '.', Mu :$test = none('.', '..'), Bool :$recursive) {
gather for dir $directory -> $path {
if $path.f && $path.basename ~~ $test {
take $path
}
if $recursive && $path.d {
.take for find-files $path, :$test
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment