Delete A Directory.....

frankbutcher

Registered User.
Local time
Today, 20:08
Joined
Aug 6, 2004
Messages
192
Hi.
I have a button to check to see if a directory exists, and to make one if not....all with help from previous threads.

All I need is the code to add to a button to delete the directory......and cannot find it anywhere!!

Can anyone help?
Thanks for reading

Frank.
 
Try this :
Code:
    Shell "cmd  /c Rmdir " & folderName & " /s /q"
 
Hi.
Thanks for the reply.
It sort of works, but I need a bit more help if thats OK. I think I should have explained more the first time!!


The code to make the directory is this.....

\\server_1\Legals\Projects\" & "CR" + CStr(Me.CR_Number)

So, if my record ID is 300, the file location will be

\\server_1\Legals\Projects\CR300.

A sub folder will also be made call health and safety so I get

\\server_1\Legals\Projects\CR300\HandS

When I run the code to delete, it deletes the HandS folder, but not the CR300 folder......

Hope this makes sense, and you can help!!

Thanks.

Frank.
 
So why not just pass \\server_1\Legals\Projects\" & "CR" + CStr(Me.CR_Number) to the folderName variable? This should delete the directory tree, including all subfolders.
 
Hi.
Thats what I was doing, and it just deletes the subfolder.
Then, when I go to the folder manually, it still won't let me delete it, until I close down access....

So, it seems that access marks it as open, so it cannot be deleted?

Wil investigate further.

Cheers

Frank.
 
VBA has an RMDIR function as well. I see no reason to Shell out to Windows to delete a directory.
 
The assumption here was that there are other files in the directory. Doesn't RMDIR return an error in such a case? By Shelling out to Windows, we can add in the parameters to delete the entire directory tree.
 
Understood and you are correct about an error being returned if all of the files in the directory are not deleted first, however I believe that is just one more line of code.
 
Hi.
Does this mean I need to use........

Shell "cmd /c Rmdir " & folderName & " /s /q"

as well as Rmdir?

If so, I am doing something wrong, as it returns the following error:-

Runtime error 75
Path/File access error.

I does delete the sub folder, but no the folder itself.
I have the rights top delete folders, as can do this via file explorer...


Where am I going wrong?

The code is as follows:-

-------------------------------------------

Dim strDirectoryPath1 As String
Dim stAppName As String



strDirectoryPath1 = "\\server_1\Legals\Projects\" & "CR" + CStr(Me.CR_Number)

If Len(Dir$(strDirectoryPath1 & "\.", vbDirectory)) <> 0 Then
Shell "cmd /c Rmdir " & "\\server_1\Legals\Projects\" & "CR" + CStr(Me.CR_Number) & " /s /q"

RmDir "\\server_1\Legals\Projects\" & "CR" + CStr(Me.CR_Number)


Else
MsgBox "The project folder does not exist!"

End If

----------------------------------------------
 

Users who are viewing this thread

Back
Top Bottom