Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - deleting populated folder problem

I can delete an empty folder with RmDir, but how do I delete a populate
folder and all its sub-folders?

Pau

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Excel VBA - deleting populated folder problem

Hi Paul,

Here is some code

Dim sFile
Dim sPath As String

sPath = "C:\NewDir\myTest"

Do
sFile = Dir(sPath & "\*.*")
If sFile < "" Then
Kill sPath & "\" & sFile
End If
Loop Until sFile = ""
RmDir sPath

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"PaulC " wrote in message
...
I can delete an empty folder with RmDir, but how do I delete a populated
folder and all its sub-folders?

Paul


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Excel VBA - deleting populated folder problem

Paul,

See www.cpearson.com/excel/Recycle.htm for information and
example code about using the SHFileOperation API call to delete a
file or folder to the recycle bin.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"PaulC " wrote in message
...
I can delete an empty folder with RmDir, but how do I delete a

populated
folder and all its sub-folders?

Paul


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Excel VBA - deleting populated folder problem

Just another way:

Function DeleteFolder(sFolder As String) As Boolean
'// Dana DeLouis
'// = = = = = = = = = =
'// Folder can have Wildcard Characters
'// True if folders with the read-only attribute set are to be deleted
'// = = = = = = = = = =
On Error Resume Next
With CreateObject("Scripting.FileSystemObject")
.DeleteFolder sFolder, True
DeleteFolder = Err.Number = 0
End With
End Function


Sub TestIt()
Dim Status As Boolean
Status = DeleteFolder("D:\Junk")
' Delete all Temp* Folders
Status = DeleteFolder("D:\Temp*")
End Sub

HTH

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"PaulC " wrote in message
...
I can delete an empty folder with RmDir, but how do I delete a populated
folder and all its sub-folders?

Paul


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - deleting populated folder problem

Thanks Bob

Code works fine. Now I am working on extending it to all the subfolder
that I have. If I can't solve this I may get back to you.

Pau

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Excel VBA - deleting populated folder problem

Pleasure Paul.

Of course you can. As a starter, I would use FileSystemObject in a recursive
routine.

If you do post back, start a new thread as this one will die shortly.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"PaulC " wrote in message
...
Thanks Bob

Code works fine. Now I am working on extending it to all the subfolders
that I have. If I can't solve this I may get back to you.

Paul


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
Excel VBA - Copy Folder problem PaulC Excel Programming 5 August 15th 04 12:08 AM
Deleting Files in Folder JEFFRO Excel Programming 5 December 14th 03 12:12 AM
VB Excel file multiple opening from a folder problem icar Excel Programming 1 September 21st 03 01:11 AM
Strange problem with a dynamically populated tabstrip on a worksheet Scott Lyon Excel Programming 0 July 29th 03 08:31 PM


All times are GMT +1. The time now is 07:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"