timehandel has asked for the wisdom of the Perl Monks concerning the following question:

hey I have written a Prgramm which reads mp3 tags and displays it, created a folder with the name of the artist and album.

Now I wanted to move the mp3 file in the new folder with the move command, but that does not work.
only if i use absolute values then the mp3 file is moving.

Perhaps someone can help me here.
I have the code in line
or die "Could not move '$ filename' to '$ cwd / $ targetdir /': $!";

as the error message it gives: Could not move '04 - Too Close.mp3 'to' G :/ perl / Alex Clare - The Lateness of the Hour / ': Permission denied at 62nd mkdir.pl line

I would also further modify the tags of the mp3 file, but I do not know what I should do there.
#!perl use warnings; use strict; use MP3::Tag; use File::Find; use File::Copy; use Cwd; my $cwd = getcwd; # Arbeitsverzeichnis + my $mp3dir = $cwd; # Default print "Pfad angeben wo die MP3's sind!!! [keine Eingabe - Aktuelles Ve +rzeichnis]\n"; while (my $input = <STDIN>) { last if $input !~ /\S/; # leere Eingabe chomp($input); if (-d $input) { # Verzeichnis existiert? $mp3dir = $input; last; } print "Verzeichnis '$input' existiert nicht. Nochmal versuchen.\n" +; } find(\&wanted, $mp3dir); # Achtung: Rekursive Suche sub wanted { return unless /\.mp3$/i; # alles was keine *.mp3 Endung + hat wird # nicht beachtet my $filename = $_; my $fullpath = $File::Find::name; return if (-d $fullpath); # Verzeichnisse mit '.mp3' weg +lassen if ($mp3 = MP3::Tag->new($fullpath)) { print "$_ (Tags: ", join(", ",$mp3->get_tags),")\n"; my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo(); print "* Song: $title\n" . "* Track: $track\n" . "* Artist: $artist\n" . "* Album: $album\n" . "* Comment: $comment\n"; my $targetdir = make_dirname_from_tags($artist, $album); if (! $targetdir) { print "Fehler beim Erzeugen des Ordnernamens!\n"; return; } if (! -d $targetdir) { # existiert noch nicht? if (! mkdir("$cwd/$targetdir")) { warn "Kann Ordner '$cwd/$targetdir' nicht anlegen: $!" +; return; } } move($fullpath, "$cwd/$targetdir/$filename"); or die "Could not move '$filename' zu '$cwd/$targetdir/':$!"; } } sub make_dirname_from_tags { # Hier diejenigen Zeichen in den Tags ersetzen, die für Ordner-/Datein +amen # verboten sind. my @tags = @_; return if ! @tags; for my $tag (@tags) { $tag =~ s/[:,]/_/g; # Zeichenklasse noch anpassen } return(join ' - ', @tags); }

Replies are listed 'Best First'.
Re: mp3 id3
by ww (Archbishop) on Jun 11, 2012 at 13:32 UTC
    Permissions?
    • Do you have permissions to traverse all dirs in the path from the source to G :/ perl / Alex Clare - The Lateness of the Hour / and write permission in that dir?
    • Is the space between the drivename, 'G,' and the colon (as shown in your report of the error message) an artifact of something here, or is it actually in your code? [update: I note that your post here on that point and your SO post are not the same. </update>]
    • Is your system one in which windoze balks at spaces in paths & filenames?

    And re "modify the tags of the mp3 file," check CPAN for the plethora of modules with 'mp3' (or /mp3/i) in their names.

      at 1:
      If I use absolute values ​​such as move ("/ TagReader/01 Casper - XOXO.mp3", "/ TagReader / Casper - Casper xoxo/01 - XOXO.mp3"); it works. Therefore, I should already have the authority.

      at 2:
      its not in the code it is only here

      at 3:
      i dont now but i think no.
      if i creat a folder i can write a name with a space between
        re 3: How about creating (with Perl) a dir with a space in its name?

        re 1: Maybe, but I'm not entirely persuaded. In your new example, you're creating a subdir in a dir that's CWD; in your code, you appear to be moving from CWD to a new drive -- is that correct?

Re: mp3 id3
by phenom (Chaplain) on Jun 11, 2012 at 12:44 UTC
    Try removing this semi-colon first:
    move($fullpath, "$cwd/$targetdir/$filename"); # <- or die "Could not move '$filename' zu '$cwd/$targetdir/':$!";
      i have remove it but the error massage is still there

      can somebody help me with my problem?
Re: mp3 id3
by tinita (Parson) on Jun 11, 2012 at 13:21 UTC