Solved

how to change Attributes of file?

Posted on 2006-06-22
6
296 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
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.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

839 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