Solved

how to change Attributes of file?

Posted on 2006-06-22
6
271 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
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now