Hi, I know how to set file attributes on Windows by using SetFileAttributes function. But I am wondering if there is a native C/C++ function can can do this too?
Thanks in advance.
Hi, I know how to set file attributes on Windows by using SetFileAttributes function. But I am wondering if there is a native C/C++ function can can do this too?
Thanks in advance.
No there is not. Neither Standard C++ nor Standard C specify such functions.
The reason for this is that there is very little commonalirty of function in this area across different operating systems. For example, UNIX-like operatimng systems have an "executable" attribute, while Windows-like operating systems use the file extension to determine executability.
If by "native", you mean in the C standard library, then no. File "attributes" are an OS specific extension, so won't appear in any standard function set. If we're willing to extend our remit to POSIX, then there are functions like fchmod, but this only handles UNIX style file modes, which are not as expressive as Windows file attributes.
In general, you can answer any question of the form "Is there a STANDARD function/object to do OS-SPECIFIC thing" by saying "Probably, if STANDARD exists only for OS. Otherwise, no".