1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| #!/usr/local/bin/perl -w
use strict;
use warnings;
sub main()
{
my $filename = "/tmp/tmpLIST";
my $flux = "";
my @AllFiles;
system
"echo \$(ls -R1 /home/f-society/Documents/informatique/infographie/*) > " . $filename; # on mets tout dans le tmp;
open(my $fh, '<:encoding(UTF-8)', $filename) # open my file
or die "Could not open file '$filename' $!";
while (my $row = <$fh>) # store all file
{
chomp $row;
$flux .= $row;
}
$flux .= " "; # for help the parsing on the last file ;)
while (my $y = substr($flux, index($flux, '/home'), index($flux, ':'))) # get all dir
{
$flux = substr($flux, index($flux, ':')+1); #remove dir ref
my $files = substr($flux, 0, index($flux, '/home')); # get all files in this dir
$flux = substr($flux, index($flux, '/home')); # remove files ref
$files =~ s/^\s+//; # remove left white space
while (my $file = substr($files, 0, index($files, ' '))) # get one file
{
$files = substr($files, index($files, ' '));
$files =~ s/^\s+//;
my $finalfile = $y . "/" . $file; # concat final path of file
push @AllFiles, $finalfile; # push it in array
}
}
my $size = scalar @AllFiles; # get array size
my $var = int(rand($size)); # gen random num
my ($ext) = $AllFiles[$var] =~ /(\.[^.]+)$/; # get ext of file
print $AllFiles[$var] . "\n" . $ext . "\n";
if ($ext eq ".pdf")
{
system "evince " . $AllFiles[$var];
}
else
{
system "deepin-image-viewer " . $AllFiles[$var];
}
}
main |
Partager