How to programmatically change directory attributes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Girgenti

    #1

    How to programmatically change directory attributes

    Hello.

    I'm trying to write a simple VS.NET 2003 VB program to delete files and
    directories on my hard drive. If the directory is read only, how do i change
    it's attribute so that i can delete it ?

    Here is some of my code. It does not error out, it just does not delete the
    directories.

    Any help would be gratefully appreciated even ideas on another way to do this.
    I'm new at all this, so any pointers that any body can give would also be
    appreciated.

    Thanks,
    Tony

    Try
    Dim dirsb() As String = Directory.GetFi les("C:\Documen ts and
    Settings\Admini strator\Local Settings\Temp")
    For Each dirx In dirsb
    Directory.Delet e(dirx, True)
    Next
    Catch ex As Exception
    Exit Try
    End Try

  • Claes Bergefall

    #2
    Re: How to programmaticall y change directory attributes

    Something like this should do it

    Try
    Dim dirsb() As String = Directory.GetFi les("C:\Documen ts and
    Settings\Admini strator\Local Settings\Temp")
    For Each dirx As String In dirsb
    Dim info As New DirectoryInfo(d irx)
    info.Attributes = Not FileAttributes. ReadOnly And info.Attributes
    Directory.Delet e(dirx, True)
    Next
    Catch ex As Exception
    End Try

    /claes



    "Tony Girgenti" <TonyGirgenti@d iscussions.micr osoft.com> wrote in message
    news:ABD680C2-F9F5-4320-A190-7AEC98E51C25@mi crosoft.com...[color=blue]
    > Hello.
    >
    > I'm trying to write a simple VS.NET 2003 VB program to delete files and
    > directories on my hard drive. If the directory is read only, how do i
    > change
    > it's attribute so that i can delete it ?
    >
    > Here is some of my code. It does not error out, it just does not delete
    > the
    > directories.
    >
    > Any help would be gratefully appreciated even ideas on another way to do
    > this.
    > I'm new at all this, so any pointers that any body can give would also be
    > appreciated.
    >
    > Thanks,
    > Tony
    >
    > Try
    > Dim dirsb() As String = Directory.GetFi les("C:\Documen ts and
    > Settings\Admini strator\Local Settings\Temp")
    > For Each dirx In dirsb
    > Directory.Delet e(dirx, True)
    > Next
    > Catch ex As Exception
    > Exit Try
    > End Try
    >[/color]


    Comment

    Working...