Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting the Read-only Property for a Folder of files

    How, in Visual Basic code, do I set on or off the Read-only property of a folder. When I experimented manually, clicking on or off the Read-only check box caused all the files contained in the folder to inherit the new setting. That is exactly what I'm trying to do. In case I get myself in trouble, I'd appreciate also knowing how to set the same property in an individual file.

    Whoever replies, thank you for your time and knowledge.

    John Littell

  2. #2
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,594
    Thanks
    5
    Thanked 1,059 Times in 928 Posts
    The read-only property for a folder does not mean read-only. See the troubleshooting section about read-only folder setting at How to modify your folder view settings.

    Joe

  3. #3
    Lounger
    Join Date
    Dec 2009
    Location
    Burlington, VT
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post
    You don't state which version of VB you're using, but I'll assume a more recent one. You can do it through the File.SetAttributes method. See http://msdn.microsoft.com/en-us/libr...es(VS.71).aspx

  4. #4
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks to Joe and Mike. You both pointed me in very different directions. Oh, I am using VB 2010 express.
    Mike: You got me to remember the File class and using SetAttributes. After some experimenting I got control of the ReadOnly attributes but for each file only. I then tried to branch out into the Directory and DirectoryInfo classes, but could find no mention of attributes or ReadOnly.

    Joe: Now that was a bit of reading. I think it said repeatedly that setting the directory flag would not set the flags in the included files. But this is not true. In my Windows 7 system, checking the RO flag in the directory properties does turn it on in every included file. And the reverse also works. I did notice that once the file attributes are set (either way), that the directory RO box simply shows a solid filler, which tells me nothing.
    As I need to do this is VB code, I suppose I could Shell to the Attrib command, but that seems awfully clumsy.

    So, as it stands, I can do the basics; that is, loop through every file in the directory and set the file attribute as needed. Or I can use Attrib to set it through the directory. Why would I want to do this? Because I need to issue a My.Computer.FileSystem.DeleteDirectory(...) method. This will fail if any of its contained files is set to read only.

    Any more ideas would be appreciated.

    John

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •