I found a script from 2008 year, that renames files to random filenames:
```
!/usr/bin/perl
randomize the filenames for the photo frame
https://www.bulkrenameutility.co.uk/forum/viewtopic.php?t=114
$dir = $ARGV[0] || die "directory?\n"; chdir($dir) || die "chdir";
opendir(D, ".") || die "opendir"; @files = grep {/jpg/} readdir(D); closedir(D);
array shuffle from perl FAQ
srand; @newfiles = (); for (@files) { my $r = rand @newfiles + 1; push(@newfiles,$newfiles[$r]); $newfiles[$r] = $_; }
if ($#files != $#newfiles) { die "$#files != $#newfiles\n"; }
while ($old = pop @files) { $new = pop @newfiles; $new =~ s/p/r/; ! -f $new || die "won't overwrite $new - check the regexp\n"; print "$old -> $new\n"; rename $old, $new || warn "rename $old -> $new: $!\n"; } ```
If I run it as perl foo.pl ./
, there is won't overwrite bar.jpg - check the regexp
error. And if I run it as perl fo.pl ./bar.jpg
, there is chdir at foo.pl line 7
error. How to make it work?
I have Perl 5.34.1 installed.
submitted by /u/Impressive-West-5839
[link] [comments]