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.
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.
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";
#!/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,
print "Current attrib: $currentattrib\n";
#Set to readonly
SetAttributes($pathToFile,
GetAttributes($pathToFile,
print "After setting to readonly: $currentattrib\n";
#Set to normal
SetAttributes($pathToFile,
GetAttributes($pathToFile,
print "After setting to normal: $currentattrib\n";
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
"SetAttributes" is not exported by the Win32::File module
"GetAttributes" is not exported by the Win32::File module
ASKER
Anybody with any clue on this....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
change this line:
use Win32::File qw(GetAttributes SetAttributes READONLY NORMAL);
to:
use Win32::File;
use Win32::File qw(GetAttributes SetAttributes READONLY NORMAL);
to:
use Win32::File;
use Win32::File qw(SetAttributes GetAttributes READONLY);
my $pathToFile = "c:/somedir/somefile.txt";
my $currentattrib = 0;
GetAttributes($pathToFile,
SetAttributes($pathToFile,