#!/usr/bin/perl -w
use strict;
use POSIX;
#use sort '_qsort';
use File::stat;


my @dirlist;
my @dirlist_new;
my $directory;
my $outputfile;
my $cd_dir;
if ($ARGV[0] !~ /-h/)
	{
		$cd_dir=$ARGV[0];
	}
else
	{
		&printhelp;
	}
print "Scanne CD- Verzeichnis\n";
#opendir($directory,$cd_dir) or die ('unable to open directory '.$cd_dir.'!');;
#@dirlist = readdir $directory;
#close($directory);
@dirlist=`ls $cd_dir`;
#
my $index=1;
#
open($outputfile,'>'.$cd_dir.'/!dirinfo.txt') or die ('unable to open file'.$cd_dir.'/!dirinfo.txt');
foreach ( @dirlist)
	{
		if( $_ ne '.' && $_ ne '..' && $_ !~ 'dirinfo')
			{
				$_ =~ s/\n//g;
				print $outputfile substr((split(/\./,uc($_)))[0],0,6)."~1.MP3:".$_."\r\n";
				print "f��ge Titel ".$index." zur Indexdatei hinzu....\r";
				$index++;
			}
	}
print "\n";
close($outputfile);	
exit 0;

sub printhelp
	{
		print "Help\n";
		print "usage: ./dirinfo.pl [cddir]\n";
		print "script for generating info file with alphabetical list of music files in a directory for Loudlink.eu audio device\n";
		print " no warranty no support. use for own risk!\n";
		exit 0;
	}

