Solved

how to change Attributes of file?

Posted on 2006-06-22
6
308 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:niravdesai23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 25

Expert Comment

by:clockwatcher
ID: 16966499
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);
0
 

Expert Comment

by:pcl99
ID: 16967819
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";
0
 

Author Comment

by:niravdesai23
ID: 16969415
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:niravdesai23
ID: 16970405
Anybody with any clue on this....
0
 
LVL 4

Accepted Solution

by:
NorCal2612 earned 50 total points
ID: 16970587
Will this work for you?

#!perl

$file = "/path/to/my_read_only_file.txt";

system("attrib -R $file");

#-----/

Hope that helped! :D

T
0
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 16970788
change this line:

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

to:

use Win32::File;
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question