![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Singapore
Posts: 77
|
Could anyone tell me how to remove a folder? or how to remove all files in a folder without fileSearch ?
Thx |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Allentown, PA
Posts: 2,512
|
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.
__________________
~Anne Troy |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Allentown, PA
Posts: 2,512
|
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
__________________
~Anne Troy |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Singapore
Posts: 77
|
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? |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Allentown, PA
Posts: 2,512
|
I'm not sure how much of a shortcut you need. Ok, so I stole it from here:
http://www.erlandsendata.no/english/...icexamples.htm I figure if he didn't offer it up here when he had a chance, it's not available. Unless, of course, it's in a newer version.
__________________
~Anne Troy |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Feb 2002
Location: Singapore
Posts: 77
|
Thx, Dreamboat.
You are a very activative and kind-hearted female here [ This Message was edited by: Andrew XJ on 2002-03-15 21:17 ] |
|
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
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 |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Feb 2002
Location: Singapore
Posts: 77
|
Great!!
Ivan, it works.Thx! |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|