File and directory permissions

I

ismael

Hi all

I have some problems to get the the permissions on windows with Perl code. I
use a simple code that run perfectly in UNIX but give me wrong information
on Windows. This is the code:

$file = "/home/ismael/pruebaperl/fichero.txt";
print "Starting to analize $file\n";
if (-e $file){
print "found\n";
}
else {
print "not found\n";
}
if (-x $file){
print "executable\n";
}
if (-r $file){
print "readable\n";
}
if (-w $file){
print "writable\n";
}
print "finished\n";

This code allways say that file is readable and writable except if is a read
only file.
is there a solution for this?, one library or code? Anything that i do
wrong?
Thanks everybody.
Best regards.
 
P

Paul Lalli

ismael said:
I have some problems to get the the permissions on windows with Perl code. I
use a simple code that run perfectly in UNIX but give me wrong information
on Windows. This is the code:

$file = "/home/ismael/pruebaperl/fichero.txt";
print "Starting to analize $file\n";
if (-e $file){
print "found\n";
}
else {
print "not found\n";
}
if (-x $file){
print "executable\n";
}
if (-r $file){
print "readable\n";
}
if (-w $file){
print "writable\n";
}
print "finished\n";

This code allways say that file is readable and writable except if is a read
only file.
is there a solution for this?

I don't know what the problem to which you're looking for a solution
is. The above file is reported as readable and writeable. Is that not
correct? And you said if it's a read-only file, it's not reported as
readable and writeable? What is it reported as?
, one library or code? Anything that i do wrong?

Well, primarily what you've done wrong is not told us what the actual
problem is. What results are you *expecting*, and what results do you
see? Be very specific.

Paul Lalli
 
I

ismael

Sorry if i wasnt very specific.
The problem is that the file dont have any permissions. It's say, nobody can
read, write or execute the file from a cmd or any program. However this
code says that the file is readable and writable. if i put the file as
"read only" the code says that is readable.

I only want to make some checks and if all its ok the execution wiil
continue in the standard way. If a file is readable make X else make Y. If
a directory is writable make X else make Y. Something like that.

Thanks you. I wish i be specific :)

Best regards
 
D

Dr.Ruud

ismael schreef:
I have some problems to get the the permissions on windows with Perl
code. I use a simple code that run perfectly in UNIX but give me
wrong information on Windows. This is the code:

$file = "/home/ismael/pruebaperl/fichero.txt";
print "Starting to analize $file\n";
if (-e $file){
print "found\n";
}
else {
print "not found\n";
}
if (-x $file){
print "executable\n";
}
if (-r $file){
print "readable\n";
}
if (-w $file){
print "writable\n";
}
print "finished\n";

This code allways say that file is readable and writable except if is
a read only file.
is there a solution for this?, one library or code? Anything that i do
wrong?

This effect has been reported some times before. I assume that you need
to use a Win32-specific module to get "better" information on files in
Windows, because the permissions-system of Windows is very different.
 
J

Joe Smith

ismael said:
I have some problems to get the the permissions on windows with Perl code. I
use a simple code that run perfectly in UNIX but give me wrong information
on Windows.
This code allways say that file is readable and writable except if is a read
only file.

How, exactly, are you setting the permissions on the Windows files?
If they are set by using the chmod() function in ActivePerl, I see
the expected results.

C:\>perl -le "for (@ARGV){open X,'>',$_;close X;chmod 0111*$_,$_}" 0 1 2 3 4 5 6 7

C:\>perl -le "print $_,'=',(-r $_?'R':'r'),(-w $_?'W':'w'),(-x $_?'X':'x') for @ARGV" ?
0=rwx
1=rwX
2=rWx
3=rWX
4=Rwx
5=RwX
6=RWx
7=RWX

Since Windows file ACLs have many more possible combinations than
simply R+W+X, it is no surprise that many of them do not correspond
to the UNIX semantics.
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top