change file attributes in a directory tree

Greetings.

Please inform me if there is a better place to ask this.

I need to, as part of an install program, change the attributes of all files under a given directory to remove the read-only attribute after they are copied from a CD. I am working in C++ (cbuilder to be exact, but I can use Win API's if I need to).
Any suggestions?

Thanks
Jeff Kish
jeff.kish@mro.com
kishjAsked:
Who is Participating?
 
AxterConnect With a Mentor Commented:
Example:

char FileName[] = "c:\\autoexec.bat";
SetFileAttributes(FileName,FILE_ATTRIBUTE_NORMAL);
0
 
AxterCommented:
You can use the SetFileAttributes() function.
0
 
AxterCommented:
You can use the FindFirstFile function with the FindNextFile function, in order to find all the files in a directory.
Then use the SetFileAttributes function to change the attributes.
0
 
kishjAuthor Commented:
Do you have a recursive snippet to go through all subdirs?
0
 
mnashadkaCommented:
Inside C++ Builder, you can use the opendir, readdir, and closedir functions to go through the directory for file names (there's an example in C++ Builder help).  Then you can use the _rtl_chmod functions to remove the read-only attributes, like:

int attrib = _rtl_chmod("C:\\temp", 0);
_rtl_chmod("C:\\temp", 1, attrib & ~FA_RDONLY);

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.

All Courses

From novice to tech pro — start learning today.