Results 1 to 7 of 7

Thread: Dir$() - Sharing Violation

Threaded View

  1. #1

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Dir$() - Sharing Violation

    Ok, this is wierd (or maybe I'm a dunce)

    Objective: decide whether or not to delete a folder.
    I test for files in a Folder, if (at least) one file exists, I don't delete the folder; whereas if there are no files I delete it.

    I use the following:
    VB Code:
    1. Private Sub Command1_Click()
    2.     If Dir$("C:\Test\Bruce\*.*", vbNormal) = vbNullString Then
    3.         Debug.Print "Folder Empty"
    4.     Else
    5.         Debug.Print "File(s) Exist"
    6.     End If
    7. End Sub

    If there is a file, I get the Debug (which is expected). But, if I try to (manualy) delete the Folder, I get a 'Sharing Violation'! - Contradicory to my Objective, but I has me wondering whay I can't delete a Folder once I run this code.......

    Here is the funny thing, If I rem out the else, It can delete the Folder???

    VB Code:
    1. Private Sub Command1_Click()
    2.     If Dir$("C:\Test\Bruce\*.*", vbNormal) = vbNullString Then
    3.         Debug.Print "Folder Empty"
    4. '    Else
    5. '        Debug.Print "File(s) Exist"
    6.     End If
    7. End Sub

    There must be an instance of the Folder open somehow post Dir$().

    I noticed this has been asked before, but no answer has been given.

    (Please note, I'm not after a workaround/alternate method, just wondering what VB is doing in this regared)

    Cheers,
    Last edited by Bruce Fox; Dec 11th, 2005 at 05:26 PM.

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