• Setting the Read-only Property for a Folder of files

    Home » Forums » Developers, developers, developers » DevOps Lounge » Setting the Read-only Property for a Folder of files

    • This topic has 3 replies, 3 voices, and was last updated 14 years ago.
    Author
    Topic
    #476034

    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

    Viewing 1 reply thread
    Author
    Replies
    • #1275716

      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

      --Joe

    • #1275859

      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/library/system.io.file.setattributes(VS.71).aspx

      • #1275951

        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

    Viewing 1 reply thread
    Reply To: Setting the Read-only Property for a Folder of files

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: