Solved

how to change Attributes of file?

Posted on 2006-06-22
6
304 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
Technology Partners: 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

Independent Software Vendors: 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!

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

696 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