Last active
October 3, 2017 15:15
-
-
Save wryk/05a0edf384261b3bb1fa39417c61b73d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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