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

Hello Perl Monks, Hoping you can help me. I am simply trying to rename a file on windows but I continue to get "Permission Denied". The file is NOT in use. If I attempt to manually rename the file it works fine.
#!/usr/local/bin/perl use strict; use warnings; use MP3::Tag; my $mp3file = "01_rascal flatts_-_ here_comes_goodbye.mp3"; my $dir="c:\\temp\\music\\"; my $file="${dir}${mp3file}"; my $mp3 = MP3::Tag->new($file); my ($title, $tracknum, $artist, $album) = $mp3->autoinfo(); print "Artist is $artist\n"; print "Album is $album\n"; print "Title is $title\n"; print "Tracknum is $tracknum\n"; if ($title && $artist) { print "OK\n"; my $rename_to="${dir}${artist}_${title}.mp3"; rename($file, "${rename_to}") or warn "Couldn't rename $file to +$rename_to: $!\n"; }
output:
C:\temp>perl mp3_rename.pl Artist is Rascal Flatts Album is Unstoppable Title is Here Comes Goodbye Tracknum is 2 OK Couldn't rename c:\temp\music\01_rascal flatts_-_ here_comes_goodbye.m +p3 to c:\temp\music\Rascal Flatts_Here Comes Goodbye.mp3: Permission +denied
Thanks

Replies are listed 'Best First'.
Re: Renaming a file
by jwkrahn (Abbot) on Dec 16, 2009 at 18:38 UTC

    Try putting this line in before you rename the file:

    $mp3->close();

      ahhh. Thank you so much.

      that worked

Re: Renaming a file
by matze77 (Friar) on Dec 16, 2009 at 18:32 UTC

    Just a thought:
    Under which user do you run the script? Are there Spaces in the filename?

    MH

      User: Administrator

      Current File Name:01_rascal flatts_-_ here_comes_goodbye.mp3

      New File Name:Rascal Flatts_Here Comes Goodbye.mp3