Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Remove complete folder tree

4 views
Skip to first unread message

pemo

unread,
Nov 8, 2006, 4:41:59 PM11/8/06
to
Anyone know of an API method to remove a complete folder tree? E.g., given
a starting folder, that folder and any sub folders are deleted - even if any
of them contain files.

Thanks

ne...@rtrussell.co.uk

unread,
Nov 8, 2006, 5:12:59 PM11/8/06
to

SHFILEOPSTRUCT shfo = {0} ;
shfo.hwnd = GetDesktopWindow() ;
shfo.pFrom = szFolderToDelete ; // Terminate with 2 NULs
shfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION ;
shfo.wFunc = FO_DELETE ;
SHFileOperation (&shfo) ;

Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.

pemo

unread,
Nov 9, 2006, 9:59:20 AM11/9/06
to
ne...@rtrussell.co.uk wrote:
> pemo wrote:
>> Anyone know of an API method to remove a complete folder tree?
>> E.g., given a starting folder, that folder and any sub folders are
>> deleted - even if any of them contain files.
>
> SHFILEOPSTRUCT shfo = {0} ;
> shfo.hwnd = GetDesktopWindow() ;
> shfo.pFrom = szFolderToDelete ; // Terminate with 2 NULs
> shfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION ;
> shfo.wFunc = FO_DELETE ;
> SHFileOperation (&shfo) ;
>

Thanks for this. However, a further question - if there's a file open in
one of the subfolders, can the whole tree be removed? I tried this using a
file opened in notepad and it worked ok. However, if I have cmd open and
its pathed to one of the subfolders I get a permission denied.

ne...@rtrussell.co.uk

unread,
Nov 9, 2006, 1:33:33 PM11/9/06
to
pemo wrote:
> Thanks for this. However, a further question - if there's a file open in
> one of the subfolders, can the whole tree be removed? I tried this using a
> file opened in notepad and it worked ok. However, if I have cmd open and
> its pathed to one of the subfolders I get a permission denied.

I don't know for sure, but I suspect the answer is no. Notepad doesn't
really keep the file 'open' - it just loads it into memory - so that
explains why it worked OK.

0 new messages