Results 1 to 9 of 9

Thread: Deleting "Read Only" file?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Deleting "Read Only" file?

    Hey, I just found a small bug in my program. When a user tries to delete a file that they have selected in the listview, and the file is a "read only" file, Runtime error '75 occurs. File Path access denied. I'm using the "Kill" function to delete files. How can I make it delete a "read-only file" without causing an error? Any help is appreciated.

  2. #2
    Hyperactive Member mikef's Avatar
    Join Date
    Jun 2000
    Location
    Beach bound...
    Posts
    510
    Check the attributes of the file first. If it is read-only, then change the attribute to -r and then KILL it.
    "If I had known it was going to be that kinda party, I would have stuck my disk in the mash potatos!"

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    How would I do that?

    How would I check the file attributes and change the read only propery? API?

  4. #4
    Addicted Member
    Join Date
    Apr 1999
    Location
    Atlanta
    Posts
    145
    something like this;

    Dim fso As New FileSystemObject
    Set fil1 = fso.GetFile("c:\YourDirectory\" & aFile)
    If fil1.Attributes = 1 Then
    fil1.Attributes = 0
    End If

    then kill it

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    multiple attributes?

    A file has more than one attribute right? Like read only, archived,etc. How do I know which one to set?

  6. #6
    Addicted Member
    Join Date
    Apr 1999
    Location
    Atlanta
    Posts
    145
    look at the file attributes in your object browser and there is a list of all the attributes. search filesystemobject and you will see the fileattribute, click on fileattribute and you will see all of the members.

  7. #7
    Addicted Member
    Join Date
    Apr 1999
    Location
    Atlanta
    Posts
    145
    oh i didn't read your question right. Just set the attribute to 0 or Normal and kill it!

  8. #8
    Gaylord Focker
    Guest
    Courchjo,

    I am not given the choice of FileSystemObject when dimming fso. You wouldn't happen to know what library I should be referancing? thx

  9. #9
    Addicted Member
    Join Date
    Apr 1999
    Location
    Atlanta
    Posts
    145
    Hey, Use the reference to Microsoft Scripting Runtime
    C:\winnt\system32\scrrun.dll

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