Created
December 18, 2018 11:00
-
-
Save jbarrett/f6c516f5cbad56d91e6154f4fd870e4b to your computer and use it in GitHub Desktop.
Very quick and dirty NTFS file renamer since ntfs-3g will happily write "invalid" filenames.
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use File::Copy qw/ mv /; | |
use File::Find (); | |
my $dir = $ARGV[0] || '.'; | |
use vars qw/*name *dir *prune/; | |
*name = *File::Find::name; | |
*dir = *File::Find::dir; | |
*prune = *File::Find::prune; | |
my $invalid_chars = qr/[*:?<>]/; | |
sub wanted; | |
File::Find::find({wanted => \&wanted}, $dir); | |
exit; | |
sub wanted { | |
my ($dev,$ino,$mode,$nlink,$uid,$gid); | |
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && | |
! -f _ | |
&& return; | |
$name !~ $invalid_chars && return; | |
printf("%s\t->\t%s\n", $name, $name =~ s/$invalid_chars/-/gr); | |
mv $name, $name =~ s/$invalid_chars/-/gr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug : should do two
File::Find::find
s - first dirs, then files.As this was a once-off I'm probably not going to update it. This is just something you should be aware of.