Link to home
Start Free TrialLog in
Avatar of niravdesai23
niravdesai23

asked on

how to change Attributes of file?

HI,
I am cpying one file from server that has Read Only attribute. I want to change its attribute so that I can write in that file.
I know , I haveto use  Win32::File module and SetAttributes command. But unfamiliar with the format and syntax.
Please reply.
Avatar of clockwatcher
clockwatcher

Here's an example:

  use Win32::File qw(SetAttributes GetAttributes READONLY);

  my $pathToFile = "c:/somedir/somefile.txt";

  my $currentattrib = 0;
  GetAttributes($pathToFile, $currentattrib);

  SetAttributes($pathToFile, $currentattrib - READONLY);
Here's the solution:
#!/usr/bin/perl -w
use strict;
use Win32::File qw(GetAttributes SetAttributes READONLY NORMAL);

my $pathToFile = "d:\\test.txt";
my $currentattrib = 0;

#See attrib
GetAttributes($pathToFile, $currentattrib);
print "Current attrib: $currentattrib\n";

#Set to readonly
SetAttributes($pathToFile, READONLY);
GetAttributes($pathToFile, $currentattrib);
print "After setting to readonly: $currentattrib\n";

#Set to normal
SetAttributes($pathToFile, NORMAL);
GetAttributes($pathToFile, $currentattrib);
print "After setting to normal: $currentattrib\n";
Avatar of niravdesai23

ASKER

I am getting following errors:.....I am using ActivePerl 5.8.8.817 for windows.


"SetAttributes" is not exported by the Win32::File module
 "GetAttributes" is not exported by the Win32::File module
Anybody with any clue on this....
ASKER CERTIFIED SOLUTION
Avatar of NorCal2612
NorCal2612

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
change this line:

use Win32::File qw(GetAttributes SetAttributes READONLY NORMAL);

to:

use Win32::File;