What's the simplest way to copy the unix file permissions of a file and set them to another file? Is there a way to store a file's permissions to a variable and then use that variable to set those permissions to another file?
Sure. Use stat()
and chmod()
(may need root).
#include <sys/stat.h>
struct stat st;
stat("/foo/bar.txt", &st);
chmod("/baz/quirk.jpg", st.st_mode);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.