FileAttributes.ReadOnly : FileAttributes « System.IO « VB.Net by API






FileAttributes.ReadOnly

  
Imports System.IO

Module Module1

    Sub ProcessTree(ByVal Dir As String)
        Dim DirObj As New DirectoryInfo(Dir)

        Dim Files As FileInfo() = DirObj.GetFiles("*.*")
        Dim Dirs As DirectoryInfo() = DirObj.GetDirectories("*.*")
 
        Dim Filename As FileInfo

        For Each Filename In Files
            Try
                If (Filename.Attributes And FileAttributes.ReadOnly) Then
                    Filename.Attributes = (Filename.Attributes And Not FileAttributes.ReadOnly)
                End If
            Catch E As Exception
                Console.WriteLine("Error changing attribute for {0}", Filename.FullName)
                Console.WriteLine("Error: {0}", E.Message)
            End Try
        Next

        Dim DirectoryName As DirectoryInfo

        For Each DirectoryName In Dirs
            Try
                ProcessTree(DirectoryName.FullName)
            Catch E As Exception
                Console.WriteLine("Error accessing {0}", DirectoryName.FullName)
                Console.WriteLine("Error: {0}", E.Message)
            End Try
        Next

    End Sub

    Sub Main()
        ProcessTree("C:\")
    End Sub

End Module

   
    
  








Related examples in the same category

1.FileAttributes.Normal
2.FileAttributes.Hidden
3.FileAttributes.Temporary