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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.