in reply to filenames with spaces causing problems

What do I need to do so that names with spaces also work? Any ideas?

The problem you're having is on the command line. When you do

mp3concat -s 700 `ls`
the results of ls become the command line for mp3concat, but if ls encounters filenames with embedded spaces, they'll appear as separate tokens on the command line. By the time these tokens get into @ARGV, it's too late.

One approach to fixing this is to have mp3concat take directory names as arguments (either instead of or in addition to filenames). Then, within the code, you could do something like

foreach my $arg ( @ARGV ) { doDir($arg), next if -d $arg; doFile($arg) if -f $arg; } ... sub doDir { my $dir = @_; opendir(D, $dir) or die "$dir: $!"; foreach my $file ( grep { -f } readdir(D) ) { doFile($file); } closedir(D); }
With a little more work, this can handle hierarchies, as well.

Another alternative is to use File::Find to traverse directories, looking for .mp3 files. If you search around the monastary, you'll find plenty of examples of using File::Find.

Replies are listed 'Best First'.
Re: Re: filenames with spaces causing problems
by drake50 (Pilgrim) on Jul 11, 2003 at 13:21 UTC
    You guys are all giving good info but let me make a quick clarification of what I'm trying to do. I'm not just moving the individual mp3s. I'm trying to move an entire cd - or entire dir that contains a bunch of mp3s. for example

    $mp3concat -s 700 "Queen/" "RATT/" "R.E.M/" "RobbieWilliams/" "Rolling Stones/" "Rush/"
    or
    mp3concat -s 700 `ls |awk '{print "\""$0"\""}'`

    As long as I quote it on the command line $file seems to have the correct value but the move still doesn't work.