Solved

change file attributes in a directory tree

Posted on 2001-08-16
5
624 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:kishj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 6392557
You can use the SetFileAttributes() function.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6392563
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
 
LVL 30

Accepted Solution

by:
Axter earned 100 total points
ID: 6392574
Example:

char FileName[] = "c:\\autoexec.bat";
SetFileAttributes(FileName,FILE_ATTRIBUTE_NORMAL);
0
 

Author Comment

by:kishj
ID: 6392628
Do you have a recursive snippet to go through all subdirs?
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 6392655
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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to programmatically differentiate between C and Java 10 218
Copy output image from TWindowsMediaPlayer 6 66
HTTPSendRequest with WinINet delays on first call 11 116
Outlook 13 98
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question