I am new to C programming and I’d like to implement chmod command on files of a dir and subdir. How can I change/show permissions with a C code? Could someone help with a example? I would appreciate if anyone can provide me a code.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s a chmod function. From man 3p chmod:
If you want to read the permissions, you’d use stat. From man 3p stat:
If you want to do it recursively like you mentioned, you’ll have to do the looping over results of
readdiryourself. Caveat!: you will have to do setting the permissions from bottom-up, because, for example, if you set the top-directory to read-only, you will not be allowed to set anything below it.