User Tools

Site Tools

This Script takes random mp3 files from $MP3LIB and copies them to $OUTDIR until a $MAXSIZE bytes were copied - It preserves directory structures. I use this script to fill my Rio Carbon Player with music from my collection (I leave some space for manual selections).

my $MAXSIZE=3*1024*1024*1024; #3 Gigs
my $MP3LIB="/ftp/mp3z/music";
my $OUTDIR="/mp3player/auto";
use File::Basename;
use File::Copy;
print "loading available files... ";
my @LIST = &getlist('',$MP3LIB);
print "found $#LIST files.\n";
print "cleaning outdir... ";
system("rm -rf $OUTDIR/");
print "done.\n";
print "copying files...\n";
my $s = 0;
while ($s < $MAXSIZE){
  my $file = splice(@LIST,int(rand scalar(@LIST)),1);
  $s += -s "$MP3LIB/$file";
  print "$file\n";
print "done.\n";
sub getlist($$){
  my $path = $_[0];
  my $base = $_[1];
  my @files = readdir(DIR);
  my @list;
  foreach my $file (@files){
    next if($file =~ /^\./);
    my $full = "$path/$file";
    if(-d "$base/$full"){
    }elsif($file =~ /\.mp3/i){
  return @list
sub dbg(){
  unless ($QUIET){
    print STDERR @_;
    print STDERR "\n";
sub mkdirp(){
  my $dir = shift();
  my @parts = split('/',$dir);
  my $path = '';
  foreach my $part (@parts){
    $path .= "/$part";
    unless(-d $path){
      my $ok = mkdir($path);
      return $ok unless($ok);
  return 1;
} · Last modified: 2006/11/13 13:32 by andi