473,394 Members | 1,694 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,394 software developers and data experts.

How can I set files read only?

I know I can use FileAttributes.Normal but it doesn't always work. I
am using the FileSystemWatcher class. I have found that if I uncheck
the read-only flag from the directory and apply to all sub folders and
files the check will go away on the file. If I use the class it never
gets unset. I wanted to know if there was a way to activate the
uncheck apply to all programatically. thanks
Oct 27 '08 #1
1 2217
jmDesktop wrote:
I know I can use FileAttributes.Normal but it doesn't always work. I
am using the FileSystemWatcher class. I have found that if I uncheck
the read-only flag from the directory and apply to all sub folders and
files the check will go away on the file. If I use the class it never
gets unset. I wanted to know if there was a way to activate the
uncheck apply to all programatically. thanks
FileSystemWatcher, as the name implies, watches. It can't be used to alter
file attributes, so I suspect you're confusing two things.

There is no built-in method for marking a directory and all subdirectories
and files as not read-only. You can manually walk the file system with (for
example) DirectoryInfo.GetFileSystemInfos() and reset the readonly attribute
yourself with .Attributes = .Attributes & ~FileAttributes.ReadOnly. Consult
the MSDN for more info on how to reset flags.

If, on the other hand, you just want to be informed when a file's attributes
change, then FileSystemWatcher could be used. You should set
..IncludeSubdirectories to true and .NotifyFilters to
NotifyFilters.Attributes to watch all files. Take note that this can
generate a large number of events.

If, on the gripping hand, you want to reset the readonly attribute of a file
you're watching with a FileSystemWatcher, first create a FileInfo instance
to it using the .FullName property of the FileSystemEventArgs you have, then
reset the readonly attribute in the manner described above.

If none of this should happen to apply, you'll have to be more specific.

--
J.
Oct 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hal Vaughan | last post by:
I am writing out archive files using ZipOutputStream with the following code: aEntry is a global Array of ZipEntries llData is a LinkedList of the data corresponding to the the ZipEntry of the...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
2
by: Michael A. Covington | last post by:
I want to deploy a project in which the user is provided with a set of READ-ONLY files to use as templates. They will be in a directory to which the user can add files of his own. It's...
6
by: gl | last post by:
I'm trying to delete a directory that contains readonly files. Is there any easy way to do this? I get a System.UnauthorizedAccessException when a read only file is encountered. Is there a way to...
4
by: knapak | last post by:
Hello I'm a self instructed amateur attempting to read a huge file from disk... so bear with me please... I just learned that reading a file in binary is faster than text. So I wrote the...
3
by: Herby | last post by:
Im rewriting a current MFC application for .NET using C++\CLI that compiles \clr SAFE. My application needs to read application settings, it used to do this from the old application ini file via...
5
by: jason735 | last post by:
Hi, I've got the following problem. I have to sort x*y elements which are in one file. I can use only an array for x elements and floor tmp files which can be read only forward. Thanks for...
3
by: masood.iqbal | last post by:
Hi, Kindly excuse my novice question. In all the literature on ifstream that I have seen, nowhere have I read what happens if you try to read a binary file using the ">>" operator. I ran into...
9
by: NvrBst | last post by:
Whats the best way to count the lines? I'm using the following code at the moment: public long GetNumberOfLines(string fileName) { int buffSize = 65536; int streamSize = 65536; long...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.