473,503 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q: Portable Way to Make Files Read Only

Hello,

I would like to recurse through a directory and make files (which match
a specific criteria) read only. From searching the Internet, I found
http://aspn.activestate.com/ASPN/Coo.../Recipe/303343
which shows how to change file attributes to read only using the
win32api module. That's great, but I was hoping there's a more portable way
to do so. Is there a more portable API call to make files read only?

Many Thanks,

Efrat
Jul 18 '05 #1
1 5198
On Sun, Feb 13, 2005 at 01:25:02PM -0600, Efrat Regev wrote:
I would like to recurse through a directory and make files (which match
a specific criteria) read only. From searching the Internet, I found
http://aspn.activestate.com/ASPN/Coo.../Recipe/303343
which shows how to change file attributes to read only using the
win32api module. That's great, but I was hoping there's a more portable way
to do so. Is there a more portable API call to make files read only?


assuming the variable "path" is set to a string indicating the file in
question, try the following:

import os
import stat

# get the current file mode
mode = os.stat(path)[stat.ST_MODE]

# set it so it is not user, group, or other writable
os.chmod(path, mode & ~stat.S_IWUSR & ~stat.S_IWGRP & ~stat.S_IWOTH)

#or

os.chmod(path,mode & ~0222)

Chris
Jul 18 '05 #2

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

Similar topics

5
2003
by: Henri Schomäcker | last post by:
Hi folks, I have a quite big class, which I want to use on UNIX-like systems and on win32. Until now, everything is absolutely portable. But now I need to read a directory and use the os...
14
2610
by: John Smith | last post by:
Hi I'm looking for a header-file only STL implementation. I know the vendors provide one with compilers but often they are either buggy or has some other problems. My problem is that under...
3
2329
by: Gautam | last post by:
Can any one tell me what are the types in C which are non portable/which make C non-portable is it a)structures, or b)unions, or 3)bit-fields, or are all of them , i am confused
10
2165
by: Jason Curl | last post by:
Dear C group, I'm very interested in writing portable C, but I only have GNU, Sparc and Cygwin to compile on. What I find is the biggest problem to writing portable C is what headers to...
9
4294
by: PengYu.UT | last post by:
Hi, I write the content of a in file "data" (in Sun Machine). Then I read "data" in both SunOS and linux. But the result is different. Do you know how to make it binary data portable. Best...
131
6018
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
14
6412
by: **--> That Guy Downstairs | last post by:
What files are needed to be #included to be able to copy files to a new directory and be portable? ie. use it in Unix (SGI and Linux) or Windows 2000. #ifdefs Ok. using dirent.h on SGI, but...
69
2567
by: Bill Reid | last post by:
This is how I handle a check that the last character of a text file is a newline: /* checks if newline is last character of text file */ unsigned check_text_file_newline_termination(FILE...
23
3304
by: asit | last post by:
what is the difference between portable C, posix C and windows C ???
0
7093
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...
0
7287
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,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
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...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
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...
0
3180
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...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.