473,785 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10603
The code for this is actually pretty straight-forward. Something like:

public void ParseFolders(st ring s_Folder)
string[] SubDirectories = Directory.GetDi rectories(s_Fol der);
if (SubDirectories .Length == 0)
{
// process this folder
}
else
{
for (int i = 0; i < SubDirectories. Length; i++)
{
ParseFolders(Su bDirectories[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.GetFi les]. Use File.GetAttribu tes to obtain the attributes. Whenever you encounter FileAttributes. ReadOnly use File.SetAttribu te 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.co m> wrote in message news:%2******** ********@TK2MSF TNGP10.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******@onlin e.microsoft.com > wrote in message news:uI******** *****@TK2MSFTNG P15.phx.gbl...
The code for this is actually pretty straight-forward. Something like:

public void ParseFolders(st ring s_Folder)
string[] SubDirectories = Directory.GetDi rectories(s_Fol der);
if (SubDirectories .Length == 0)
{
// process this folder
}
else
{
for (int i = 0; i < SubDirectories. Length; i++)
{
ParseFolders(Su bDirectories[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.GetFi les]. Use File.GetAttribu tes to obtain the attributes. Whenever you encounter FileAttributes. ReadOnly use File.SetAttribu te 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.co m> wrote in message news:%2******** ********@TK2MSF TNGP10.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
3147
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 or unix filesystem? Thanks
2
1594
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 you can imagine, this is sometimes a pain in the ... When I go back to working on the computer with VS.Net installed, I copy any newly created files and folders from the live server onto the local machine for further dev work.
4
3782
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 testing purposes, the secure place is setup on the client machine. The client (window app) calls the web service (on a different machine) and connects successfully to the web service. However, when client calls a method that copies the file from...
3
1920
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 - the path to the corresponding file and call submit with the script. Thank you.
1
9913
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 some custom actions to change the permissions on the install directory and its sub folders/files so that they can be accessed correctly via a network share later on. We would want to add Everyone full access to the install directory (its
0
1336
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 the same root destination folder. Whereas my program needs files which are in different folders in the project root folder. How can I create a setup.exe that can distribute the files to the corresponding program folders, after re-creating them all....
1
4748
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 and folders , and put files into folders , sub folders etc. 2. every object in the cache can be accessed via: name , but also based on some unique ID , for example , the hash of the file data. 3. deleting folder will delete all it's sub folders &...
2
13263
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 seems like i need to use file.delete and directory.delete at the same time.
1
2321
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. Thanks, Naren Dim myNamespace As Outlook.NameSpace
4
2117
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 php script is executed, what I'm really looking for is a way to loop through all the folders. Thanks in advance!
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.