473,545 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q: Is file readable by all users?

Hi,

Would something like:

if (-r $name) {
: # do nothing
} else {
print "File is not readable...\n";
}

be enough to test if a file is readable by all users?
I'm a little unsure which bit does the -r relate to.

What about if I wanted to test whether the file is readable by the owner's
group but not everyone else?

Cheers
Jul 19 '05 #1
4 3362

"Troll" <ab***@microsof t.com> wrote in message
news:MD******** ************@ne ws-server.bigpond. net.au...
Hi,

Would something like:

if (-r $name) {
: # do nothing
} else {
print "File is not readable...\n";
}

be enough to test if a file is readable by all users?
I'm a little unsure which bit does the -r relate to.

What about if I wanted to test whether the file is readable by the owner's
group but not everyone else?

Cheers

I had a look at stat and can read the permissions. But what I need to do
then is change the file permissions ONLY if the file is not readable by all
users.
Should I be trying to capture the output of:

$mode = (stat "test.txt") [2];
printf "%0\n", $mode & 07777; # this gives me the original permissions

and then sed-ing it so as to read the last character? If the last char > 3
then the file is readable by all users.
How can I assign the above printf output to a scalar?

Any pointers welcome :)

Jul 19 '05 #2
*snip*
I had a look at stat and can read the permissions. But what I need to do
then is change the file permissions ONLY if the file is not readable by all users.
Should I be trying to capture the output of:

$mode = (stat "test.txt") [2];
printf "%0\n", $mode & 07777; # this gives me the original permissions

and then sed-ing it so as to read the last character? If the last char > 3
then the file is readable by all users.
How can I assign the above printf output to a scalar?

Any pointers welcome :)


Ok, got it.
$permissions = sprintf "%0\n", $mode & 07777;

Silly Q: How do I check if the last digit is > 3? My mind is blank atm...

Jul 19 '05 #3
*snip*
then the file is readable by all users.
How can I assign the above printf output to a scalar?

Any pointers welcome :)


Ok, got it.
$permissions = sprintf "%0\n", $mode & 07777;

Silly Q: How do I check if the last digit is > 3? My mind is blank atm...

Is there something simpler than:
if ($permissions =~ m/^..[4-7]/) {

Thanks.


Jul 19 '05 #4
"Troll" <ab***@microsof t.com> wrote in message news:<MD******* *************@n ews-server.bigpond. net.au>...
Hi,

Would something like:

if (-r $name) {
: # do nothing
} else {
print "File is not readable...\n";
}

be enough to test if a file is readable by all users?
I'm a little unsure which bit does the -r relate to.

What about if I wanted to test whether the file is readable by the owner's
group but not everyone else?

Cheers


The -r test only checks if the user running the program can read that
file.
To check if all users can read a file use the 'mode' returned by the
stat() function (3rd returned element).

use Fcntl ':mode';

$mode = (stat($filename ))[2];
$other_read = $mode & S_IROTH;

Check 'perldoc perlfunc' for a full example on how to interpret
'mode'.

Hope that helps.

Irene
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1727
by: Dave Smithz | last post by:
Hi there, As a newbie to PHP is it in anyway possible for a casual web surfer to actually get to see the PHP behind my .php file. E.g. if index.php contained PHP code to check if the page had been called with a variable such as "password", is there anyway a public member can get to see the raw php file and therefore see what the...
6
24161
by: Hal Vaughan | last post by:
I've been reading up on file permissions (including FilePermission, Permission, and Permissions). From what I see, these are temporary and forgotten when a program exits (if I'm wrong, tell me, please). I'm installing a program on a computer and that includes configuration files that change regularly. When I create the configuration files,...
13
3399
by: raykyoto | last post by:
Hi all, I'm sure this is a popular question that comes up every few months here. Indeed, I've looked at some of the past postings, but I would like to ask things differently. Basically, I'm using a flat file to storing data. I have to do this because mySQL is not installed on my web server, and I am not the root user. The amount of...
10
5552
by: MLH | last post by:
I print to a device that creates a PDF. Knowing the filename, how can I then embed the PDF into the body text of an OutLook Express outbound email & send to a specified address in a table? I want recipient addressees to see the report in the body text window of their email when they open it. I was thinking also about attaching the PDF file to...
2
1201
by: meh | last post by:
I have a very huge database in MS access 2000. I want only few people to make changes to it and rest should be able to display only. Can someone please show me how to do it ? Thanks.
9
4311
by: steph_de_marseille | last post by:
I would like to write a x array in a file. If the array has a small numbers of columns I know I can use a loop like: int i,j; double array; FILE *file1; file1=fopen("data.dat","w"); for(i=0;i<50;i++){
9
8366
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. However, after I alter the table and open microsoft excel to look at any changes; I get the following error: "This file is not in a recognizable...
77
2538
by: ume$h | last post by:
/* I wrote the following program to calculate no. of 'a' in the file c:/1.txt but it fails to give appropriate result. What is wrong with it? */ #include"stdio.h" int main(void) { FILE *f; char ch; long int a=0;
30
1938
by: Adam Baker | last post by:
Hello, I'm writing a site where a handful of people will be able to edit the content using PHP scripts (FCKeditor). The content is stored as individual files in a directory. I'd like to validate the "editors" using PHP, cookies, etc. The question is what file permissions I need to allow for the content to be writable by my PHP script. Do I...
0
7499
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7689
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7943
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7786
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5359
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.