Simple script to select a random file from the filesystem.

This commit is contained in:
hjp 2005-08-16 08:25:06 +00:00
parent 496e9a3fc8
commit 6a46455436
2 changed files with 29 additions and 0 deletions

7
random_file/GNUmakefile Normal file
View File

@ -0,0 +1,7 @@
include GNUmakevars
all: random_file
clean:
true
install: $(BINDIR)/random_file
include GNUmakerules

22
random_file/random_file Executable file
View File

@ -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);
}
}