Using File::Find to generate playlists

2004-01-07 Thread Alan
Ok, please don't laugh.  This is my very first shot at Perl and if I 
learn something, I'll be putting it to use for more important tasks.

Thanks in advance for any comments.


#!/usr/bin/perl

# A dorkey little perl script using File::Find.  The idea is to recurse
# subdirectories and write an .ASX file (sequenced playlist of file 
# names) to each subdirectory for the files located there.

# Aside from the slight This doesn't work as expected problem ...
# the following I haven't yet figured out:
#
# 1. The 'outfile.asx' needs to take its name from the current directory
#name and not be arbitrarily set to some predefined name 
#(outfile.asx in this case). Maybe munge the fully qualified path 
#somehow, or go back to READDIR? g
#
# 2. How does one set the top directory for File::Find to the directory
#in which the script is run?

use strict;
use warnings;
use File::Find;

find ( {
   wanted = \wanted,
   preprocess = \preprocess,
}, @ARGV);

sub wanted {
   if (-f _) { # check for avi, mpg, mpeg, divx, etc.?
  open( OUTFILE, $File::Find::dir/outfile.asx )
 or die( Cannot open $File::Find::dir/ .outfile.asx: $! );
  print( OUTFILE Entry\n );
  print( OUTFILERef href = \$File::Find::name\\n );
  print( OUTFILE Entry \n\n );
  close( OUTFILE ) 
 or die( Cannot close $File::Find::dir/ . outfile.asx: $! );
   }
}

sub preprocess {
   print Processing directory $File::Find::dir ...\n;
   open( OUTFILE, $File::Find::dir/outfile.asx )
  or die( Cannot open $File::Find::dir/ . outfile.asx: $! );
   print( OUTFILE Asx Version = \3.0\\n );
   print( OUTFILE Title/Title\n );
   print( OUTFILE Abstract/Abstract\n );
   print( OUTFILE Copyright/Copyright\n );
   print( OUTFILE Author/Author\n\n );
   close( OUTFILE ) 
 or die( Cannot close $File::Find::dir/ . outfile.asx: $! );

   sort { uc $a cmp lc $b } @_;
}




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Using File::Find to generate playlists

2004-01-07 Thread Dan Muey
 Ok, please don't laugh.  This is my very first shot at Perl and if I 
 learn something, I'll be putting it to use for more important tasks.
 
 Thanks in advance for any comments.
 
 
 #!/usr/bin/perl
 
 # A dorkey little perl script using File::Find.  The idea is 
 to recurse # subdirectories and write an .ASX file (sequenced 
 playlist of file 
 # names) to each subdirectory for the files located there.
 
 # Aside from the slight This doesn't work as expected 
 problem ... # the following I haven't yet figured out: # # 1. 
 The 'outfile.asx' needs to take its name from the current directory
 #name and not be arbitrarily set to some predefined name 
 #(outfile.asx in this case). Maybe munge the fully qualified path 
 #somehow, or go back to READDIR? g
 #
 # 2. How does one set the top directory for File::Find to the 
 directory
 #in which the script is run?
 
 use strict;
 use warnings;
^^^
Excellent!! Bravo! :)
If I can I'll look at your questions in a bit.

 use File::Find;
 
 find ( {
wanted = \wanted,
preprocess = \preprocess,
 }, @ARGV);
 
 sub wanted {
if (-f _) { # check for avi, mpg, mpeg, divx, etc.?
   open( OUTFILE, $File::Find::dir/outfile.asx )
  or die( Cannot open $File::Find::dir/ .outfile.asx: $! );
   print( OUTFILE Entry\n );
   print( OUTFILERef href = \$File::Find::name\\n );
   print( OUTFILE Entry \n\n );
   close( OUTFILE ) 
  or die( Cannot close $File::Find::dir/ . 
 outfile.asx: $! );
}
 }
 
 sub preprocess {
print Processing directory $File::Find::dir ...\n;
open( OUTFILE, $File::Find::dir/outfile.asx )
   or die( Cannot open $File::Find::dir/ . outfile.asx: $! );
print( OUTFILE Asx Version = \3.0\\n );
print( OUTFILE Title/Title\n );
print( OUTFILE Abstract/Abstract\n );
print( OUTFILE Copyright/Copyright\n );
print( OUTFILE Author/Author\n\n );
close( OUTFILE ) 
  or die( Cannot close $File::Find::dir/ . 
 outfile.asx: $! );
 
sort { uc $a cmp lc $b } @_;
 }
 
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED] 
http://learn.perl.org/ http://learn.perl.org/first-response



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response