|
-
Dec 11th, 2005, 05:21 PM
#1
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:
Private Sub Command1_Click()
If Dir$("C:\Test\Bruce\*.*", vbNormal) = vbNullString Then
Debug.Print "Folder Empty"
Else
Debug.Print "File(s) Exist"
End If
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:
Private Sub Command1_Click()
If Dir$("C:\Test\Bruce\*.*", vbNormal) = vbNullString Then
Debug.Print "Folder Empty"
' Else
' Debug.Print "File(s) Exist"
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|