Simple script to select a random file from the filesystem.
This commit is contained in:
parent
496e9a3fc8
commit
6a46455436
|
@ -0,0 +1,7 @@
|
|||
include GNUmakevars
|
||||
all: random_file
|
||||
clean:
|
||||
true
|
||||
install: $(BINDIR)/random_file
|
||||
|
||||
include GNUmakerules
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
my $p = $ARGV[0] || "/";
|
||||
|
||||
for (;;) {
|
||||
opendir(D, $p);
|
||||
my @f = grep {! /^\.\.?$/ } readdir(D);
|
||||
close(D);
|
||||
if (!@f) {
|
||||
# empty or unreadable directory
|
||||
print "$p\n";
|
||||
exit(0);
|
||||
}
|
||||
my $f = $f[rand($#f + 1)];
|
||||
$p = "$p/$f";
|
||||
if (! -d $p) {
|
||||
print "$p\n";
|
||||
exit(0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue