473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Recursively Set All Folders & Files to NOT Read-Only

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
2 10507
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ruby Tuesday | last post by:
Is there a fast way to read files/directory recursively? Instead of inspecting each file(s)/dir(s), is there a way to know that its a file or a directory from its hidden attribut both for windows...
2
by: Jon Maz | last post by:
Hi All, I'm in a possibly unusual situation, that is working alternately on an ASP.NET web site from two dev computers, one of which has VS.Net installed on it, the other of which does not. As...
4
by: Khalique | last post by:
I have built a web service whose purpose is to copy files from a secure place to client machine and vice versa. The problem I am having is perhaps related to permissions and access rights. For...
3
by: Kamen TOMOV | last post by:
Hi, Is uploading recursively directories to a web server possible with JavaScript? I mean is it possible read a directory recursively and dynamically construct <input type="file"> with value...
1
by: Aek | last post by:
What is the best way to recursively change the permissions of the directory we are installing into? Is there a nice way to do this in C# ..NET? We are using an MSI installer and will need to add...
0
by: bendavid | last post by:
Hello, I work on WinXP SP1. with VB6 - MS-Access(VisData). I created a setup.exe using Package and Deployment Wizard for VB 6. But when the program is installed all the files are installed to...
1
by: semedao | last post by:
Hi all, I'm looking for some example , open source etc code that implement caching of files and folders with those requirments: 1. like every file system , I can write , read , delete etc files...
2
by: halimunan | last post by:
hello all, how do i delete all folders and files inside a directory while at the same time keeping(not deleting the directory) ? e.g : i want to delete all folders and files inside c:\temp it...
1
NarenMCA
by: NarenMCA | last post by:
Hi, The below code in MS Outlook gives me the names of folders in "public folders". I am looking forward to get all the subfolders and files in "Public folders" Please assist me in this. ...
4
MarkoKlacar
by: MarkoKlacar | last post by:
Hi, Is there a way to recursively select folders and upload the files in the current, so to speak, folder? I know that there exists a possibility to upload a file in the same folder that the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.