I'm learning to code, following tutorials to try and fix a problem that's been annoying - to clean up files on macOS so they don't jam OneDrive from working.
I have followed several tutorials and it's very nearly doing what I'd hope.
#!/usr/bin/perl -w
use strict;
use warnings;
use File::Find;
my @argv;
my $dir = $ARGV[0];
find(\&dirRecurs, $dir);
sub dirRecurs{
if (-f and not 's/^\./' )
{
(my $txt = $_) =~ s/^\ | (?=\.)|[\/!#%^?*&()\\]| $//g;
rename($_, $txt);
}
}
I expected it to exclude .dotfiles
from the renaming process as a result of and not 's/^\./'
but it doesn't. If I remove the and not 's/^\./'
from the if line, all works as I'd hope, except
I expected \/
in the regex to rename files like more/less.pdf
but it doesn't