By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,451 Members | 1,613 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,451 IT Pros & Developers. It's quick & easy.

Recursively Set All Folders & Files to NOT Read-Only

P: n/a
Hello,
I've been struggling with a function(s) to recursively set all folders and
files to NOT read-only. So, I thought I'd post this message.

What I need to do is: given a starting path, I need to recursively go
through all files and folders below the starting path and check if the file
or folder is read-only and, if so, set it to not read-only.

Any ideas?

Thanks!!!
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
The code for this is actually pretty straight-forward. Something like:

public void ParseFolders(string s_Folder)
string[] SubDirectories = Directory.GetDirectories(s_Folder);
if (SubDirectories.Length == 0)
{
// process this folder
}
else
{
for (int i = 0; i < SubDirectories.Length; i++)
{
ParseFolders(SubDirectories[i]);
}
// process this folder
}
}

will recursively parse a directory tree rooted at path s_Folder. For each folder, you would simply have to check the attributes of the folder itself as well as those of each file it contains [which you can obtain using Directory.GetFiles]. Use File.GetAttributes to obtain the attributes. Whenever you encounter FileAttributes.ReadOnly use File.SetAttribute to set the attributes to FileAttributes.Archive (or some other member of the FileAttributes enumeration).

I hope this helps.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

"melo" <me**@nospam.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello,
I've been struggling with a function(s) to recursively set all folders and
files to NOT read-only. So, I thought I'd post this message.

What I need to do is: given a starting path, I need to recursively go
through all files and folders below the starting path and check if the file
or folder is read-only and, if so, set it to not read-only.

Any ideas?

Thanks!!!

Nov 16 '05 #2

P: n/a
Thank you. I'll have a closer look at your solution. But, you're right, it does seem pretty straight forward now that I see your ideas.

"Kai Brinkmann [MSFT]" <ka******@online.microsoft.com> wrote in message news:uI*************@TK2MSFTNGP15.phx.gbl...
The code for this is actually pretty straight-forward. Something like:

public void ParseFolders(string s_Folder)
string[] SubDirectories = Directory.GetDirectories(s_Folder);
if (SubDirectories.Length == 0)
{
// process this folder
}
else
{
for (int i = 0; i < SubDirectories.Length; i++)
{
ParseFolders(SubDirectories[i]);
}
// process this folder
}
}

will recursively parse a directory tree rooted at path s_Folder. For each folder, you would simply have to check the attributes of the folder itself as well as those of each file it contains [which you can obtain using Directory.GetFiles]. Use File.GetAttributes to obtain the attributes. Whenever you encounter FileAttributes.ReadOnly use File.SetAttribute to set the attributes to FileAttributes.Archive (or some other member of the FileAttributes enumeration).

I hope this helps.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

"melo" <me**@nospam.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello,
I've been struggling with a function(s) to recursively set all folders and
files to NOT read-only. So, I thought I'd post this message.

What I need to do is: given a starting path, I need to recursively go
through all files and folders below the starting path and check if the file
or folder is read-only and, if so, set it to not read-only.

Any ideas?

Thanks!!!

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.