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 56 57 58
#!/usr/bin/perl -T use Benchmark; my $t0 = Benchmark->new; use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use utf8; use open qw/:std :utf8/; use encoding 'utf8'; use FileHandle; my $search_dir = "/media/MediaLibrary/Audio"; my $database = "/var/www/testDB.dat"; print "Content-type: text/html; charset=utf-8\n\n"; my @mp3s = &GetTheFiles( $search_dir ); my $t1 = Benchmark->new; my $td = timediff($t1, $t0); my $benchmarktime = timestr($td); print "<br/>\n<br/>\n".$benchmarktime; sub GetTheFiles { my @dirs = @_; my (@allfiles, @files) = (); my ($currdir, $file) = ""; while (@dirs != 0) { $currdir = pop( @dirs ); opendir( ENTRIES, "$currdir/" ); @allfiles = readdir( ENTRIES ); closedir( ENTRIES ); for $file (@allfiles) { if (-d "$currdir/$file") { push( @dirs, "$currdir/$file" ) if (($file ne ".") && ($file ne "..")); } else { my $entry = "$currdir/$file"; utf8::encode($entry); print $entry."<br/>\n"; my $fh = FileHandle->new('>>' . $database) || die "Could not open $database - $_"; print $fh "$entry\n"; $fh->close || die "Could not close $database - $_"; } } } return 0; } # EOF
1
2
3
4
5
6
7
8
9
/media/MediaLibrary/Audio/Bj�rk<br/>
/media/MediaLibrary/Audio/Die �rzte<br/>
/media/MediaLibrary/Audio/D�sert Blues<br/>
/media/MediaLibrary/Audio/Herbert Gr�nemeyer<br/>
/media/MediaLibrary/Audio/H�rspiele<br/>
/media/MediaLibrary/Audio/Schr�ders<br/>
<br/>
<br/>
7 wallclock secs ( 0.70 usr + 0.90 sys = 1.60 CPU)
1
2
3
4
5
6
/media/MediaLibrary/Audio/Bj�rk
/media/MediaLibrary/Audio/Die �rzte
/media/MediaLibrary/Audio/D�sert Blues
/media/MediaLibrary/Audio/Herbert Gr�nemeyer
/media/MediaLibrary/Audio/H�rspiele
/media/MediaLibrary/Audio/Schr�ders
ls | hexdump -C
1
2
3
4
ls | hexdump -C | grep Die
00000560 20 4e 6f 20 41 6e 67 65 6c 0a 44 69 65 20 48 61 | No Angel.Die Ha|
00000570 70 70 79 0a 44 69 65 20 8e 72 7a 74 65 0a 44 69 |ppy.Die .rzte.Di|
00000d90 72 6c 65 6e 65 20 44 69 65 74 72 69 63 68 0a 4d |rlene Dietrich.M|