in reply to Flattening a directory tree in a filesystem
There are probably saner ways to deal with collisions; Being able to know where it came from might be very nice.use warnings; use strict; use File::Find; use File::Spec::Functions; use Time::HiRes; use File::Copy; my $root = "/path/to/root" find(\&wanted, $root); sub wanted { if (File::Find::dir eq $root) { print "$_ is already in the root folder $root\n"; } else { my $target = catfile($root, $_); if (-f $target) { my $microtime = join '.', Time::HiRes::gettimeofday(); print "Filename collision, appending $microtime to $_ before mo +ving\n"; move($File::Find::name, $target . $microtime); } else { print "Moving " . $File::Find::name . " to $target\n"; move($File::Find::name, $target) } } }
|
|---|