Results 1 to 3 of 3

Thread: [RESOLVED] [2008] Delete Read Only files

  1. #1

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Resolved [RESOLVED] [2008] Delete Read Only files

    My app is all but finished, just running through some final tests and I have discovered that I'm having trouble getting my program to delete read-only files ... unless I do it manually through Explorer I cannot seem to rid them, and I get an exception on debug.

    So my question is how can I force it to delete a read only file.

    I'm currently using

    Code:
    System.IO.Directory.Delete(tempdir, True)
    to delete the dir and all its files. All goes well except for the read-only ones...
    -BoKu-

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2008] Delete Read Only files

    Hi,

    You could, before deleting the file change it to normal and then delete it.
    Here's an example how to change it to normal:

    vb Code:
    1. System.IO.File.SetAttributes(path, System.IO.FileAttributes.Normal)

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Re: [2008] Delete Read Only files

    Cheers for the hint sparrow

    I wrote a little script that will change all files in a directory to normal recursively

    Code:
    For Each item In System.IO.Directory.GetFiles(tempdir)
    System.IO.File.SetAttributes(item, IO.FileAttributes.Normal)
    Next
    -BoKu-

Posting Permissions

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



Click Here to Expand Forum to Full Width