in VBA, can i remove a folder without FileSearch?

Andrew XJ

Board Regular
Joined
Feb 21, 2002
Messages
77
Could anyone tell me how to remove a folder? or how to remove all files in a folder without fileSearch ?
Thx
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Well, you can delete all the files in a folder with this line:

kill "c:foldername*.*"

But I can't work out how to delete a folder.
 
Upvote 0
Just found it and stole it:

How to delete a folder (folder must be empty):

RmDir "NewPrivateFolder"
' deletes the subfolder NewPrivateFolder in the active folder
RmDir "F:My DocumentsNewPrivateFolder"
' deletes the subfolder NewPrivateFolder in the folder F:My Documents
 
Upvote 0
thx.
In fact i know from the help file that if i delete folder, the folder must be empty. So i still need to use Kill to delete all files in every sub folder first. Is it? No shortcut?
 
Upvote 0
Thx, Dreamboat. :), I have changed my mind and now i use FileSystemObject to move whole folder to another place instead of delete the original dirty folder.
You are a very activative and kind-hearted female here :)
This message was edited by Andrew XJ on 2002-03-15 21:17
 
Upvote 0
Try this then;

Sub RemoveDir_WithFiles()
Dim Fs As Object

On Error GoTo DelErr
'CAUTION: Will delete entire Folder NO PROMPT
Set Fs = CreateObject("Scripting.FileSystemObject")
Fs.DeleteFolder "C:mydir", True

Exit Sub
DelErr:
MsgBox Err.Number & vbCr & _
Err.Description
End Sub


Ivan
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top