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

I am attempting to change the ID tags on my MP3 files, but before I do that, I have to remove the Read Only permission from the file, so that I can write to it. The documentation that comes with Win32::File is very vague, and I was wondering if there's any monks out there who understand this module. Thanks.
#!C:\Perl\bin\perl -w use strict; use File::Slurp; use Win32::File; use MP3::ID3v1Tag; my @Directories=("C:\\MP3Disc1","C:\\MP3Disc2","C:\\MP3Disc3","C:\\MP3 +Disc4"); my $Dir; my @Files; my $File; my $attr; my $path; my $MP3; foreach $Dir(@Directories){ @Files=read_dir($Dir); foreach $File(@Files){ $path=$Dir."\\".$File; Win32::File::GetAttributes($path,$attr); Win32::File::SetAttributes($path,$attr|NORMAL); $MP3=new MP3::ID3v1Tag($path); my($artist,$title)=split " - ",$File; $MP3->set_artist($artist); $MP3->set_title($title); $MP3->save(); } }
This is being done with ActiveState Perl 5.6 Build 626 on a Windows 95 system.
TStanley
--------
There's an infinite number of monkeys outside who want to talk to us
about this script for Hamlet they've worked out
-- Douglas Adams/Hitchhiker's Guide to the Galaxy

Replies are listed 'Best First'.
(tye)Re: Problem with ActiveState's Win32::File module
by tye (Sage) on Jul 31, 2001 at 05:32 UTC

    s/|NORMAL/&~READONLY/ to your code should be enough. The attributes are simple bit masks so you need to remove the READONLY bit.

    Update: This module is just a wrapper around [SG]etFileAttributes which says this about FILE_ATTRIBUTE_NORMAL: "The file or directory has no other attributes set. This attribute is valid only if used alone." Which I found rather funny as any directory is going to have the FILE_ATTRIBUTE_DIRECTORY bit set. The documentation also talks about "the handle" (what handle?). But whatever.

            - tye (but my friends call me "Tye")
Re: Problem with ActiveState's Win32::File module
by John M. Dlugosz (Monsignor) on Jul 31, 2001 at 06:33 UTC
    For removing the read-only attribute under Windows, I found that chmod works just fine. I did it that way in a script where I needed it, for portability. No special module needed.

    —John

Re: Problem with ActiveState's Win32::File module
by bikeNomad (Priest) on Jul 31, 2001 at 05:37 UTC
    Why don't you just reset the READONLY bit (I don't do Win32 stuff much, but just glanced at the docs)? I have no idea what NORMAL is, but I don't think there's a DOS attrib for that...

    Win32::File::GetAttributes($path, $attr); Win32::File::SetAttributes($path, $attr & ~ READONLY);
      NORMAL is no bits set. So you obviously can't use that to change anything! But it's used in directory list filtering and in creating files with the desired attributes.

      —John

      (P.S. the value of the constant is actually 128. But ORing that in doesn't make the other bits (READONLY=1) go away. Perhaps setting it, not ORing it in, works.)

Re: Problem with ActiveState's Win32::File module
by eejack (Hermit) on Jul 31, 2001 at 06:37 UTC
    And just because there is always more than one way to do it...

    Looking over the info on this page I found you could do a

    exec (C:\Windows\command\attrib -R $path\*);
    to remove the read only flag.

    EEjack

Re: Problem with ActiveState's Win32::File module
by earthboundmisfit (Chaplain) on Jul 31, 2001 at 06:06 UTC
    Is it possible these files have additional security? Win32::FileSecurity seems like something that might help you debug it. Enumerate the current mask on your files and at least you'll be able to tell what's going. The doc has some good examples.