yeungsprite
Programmer
Hi,
I am having a problem deleting a folder that is created within VB. When I try and delete the folder, I get a message: "Run-time error '75': Path/File access error". The folder cannot be deleted manually either, and displays the message "There has been a sharing violation. The source or destination file may be in use". The issue may be able to be resolved by using the ChDir command, but I am unsure of how to accomplish this. I have included sample code at the bottom.
Regards,
Andrew
-----------------------------------
Dim Reply As Integer
Dim tmpfolder As String
tmpfolder = "C:\tempfolder"
' check if directory exists
If Len(Dir(tmpfolder, vbDirectory)) > 0 Then
Reply = MsgBox("Directory exists, Delete?", vbYesNo, "Delete Folder & Contents and create New Folder?"
If Reply = 6 Then ' Yes delete folder
If Len(Dir(tmpfolder & "\", vbNormal)) > 0 Then 'not an empty directory
'delete files
Kill (tmpfolder & "\*.*"
End If
'delete folder
RmDir (tmpfolder) <---break point
Exit Sub
Else
If Reply = 7 Then ' No, don't delete folder
MsgBox ("No Directory created"
Exit Sub
End If
End If
End If
'Create new directory
MkDir tmpfolder
I am having a problem deleting a folder that is created within VB. When I try and delete the folder, I get a message: "Run-time error '75': Path/File access error". The folder cannot be deleted manually either, and displays the message "There has been a sharing violation. The source or destination file may be in use". The issue may be able to be resolved by using the ChDir command, but I am unsure of how to accomplish this. I have included sample code at the bottom.
Regards,
Andrew
-----------------------------------
Dim Reply As Integer
Dim tmpfolder As String
tmpfolder = "C:\tempfolder"
' check if directory exists
If Len(Dir(tmpfolder, vbDirectory)) > 0 Then
Reply = MsgBox("Directory exists, Delete?", vbYesNo, "Delete Folder & Contents and create New Folder?"
If Reply = 6 Then ' Yes delete folder
If Len(Dir(tmpfolder & "\", vbNormal)) > 0 Then 'not an empty directory
'delete files
Kill (tmpfolder & "\*.*"
End If
'delete folder
RmDir (tmpfolder) <---break point
Exit Sub
Else
If Reply = 7 Then ' No, don't delete folder
MsgBox ("No Directory created"
Exit Sub
End If
End If
End If
'Create new directory
MkDir tmpfolder