| re: Recursively Set All Folders & Files to NOT Read-Only
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]" <kaibrink@online.microsoft.com> wrote in message news:uI2sQgDJFHA.588@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" <melo@nospam.com> wrote in message news:%23da9SwCJFHA.2844@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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!!!
>
>[/color] |