Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

How can I know if a file is read only?

I developpe an application using visual c++ 6.0 and I need to get information on read only property of some file before overwrite them. How can I do this?
0
chouproute
Asked:
chouproute
  • 3
1 Solution
 
AxterCommented:
You can use the stat function or the windows API function GetFileAttributes
0
 
AxterCommented:
DWORD attributes = GetFileAttributesA(srcPath);

if (attributes & FILE_ATTRIBUTE_READONLY)
{
   //It's a read only file
}
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi chouproute,

call stat() on the file.  One of the fields is the file's flags, which include the READONLY property.

Of course, it's probably easiest to just open the file for write.  If the open fails, check errno.  If errno is EROFS or EACCES then the file or filesystem is read-only and the application can not write to it.



Good Luck,
Kent
0
 
AxterCommented:
struct stat my_stat;
stat(FileName, &my_stat);

if  ( ! (my_stat.st_mode &  S_IWRITE) && (my_stat.st_mode &  S_IREAD) )
{
  //It's a read only file
}
0
 
sarangk_14Commented:
You might find the following links useful:

http://www.devasp.net/net/articles/display/624.html
http://msdn2.microsoft.com/en-us/library/fa0hc0ht(VS.80).aspx

Frankly, I wouldn't bet my life on it, as my knowledge of VC++ can be described as moderate at best ;-)

Hope this helps.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now