# How to call SHFileOperation API to recursively delete files and folders

**URL:** <https://clarionhub.com/t/how-to-call-shfileoperation-api-to-recursively-delete-files-and-folders/5172>\
**Category:** questions\
**Tags:** c6, winapi\
**Created:** [June 3, 2022, 2:04pm UTC](https://clarionhub.com/t/how-to-call-shfileoperation-api-to-recursively-delete-files-and-folders/5172 "2022-06-03T14:04:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkuijt](https://clarionhub.com/user_avatar/clarionhub.com/jkuijt/32/6168_2.png) [@jkuijt](https://clarionhub.com/u/jkuijt)\
**Post date:** [June 3, 2022, 2:04pm UTC](https://clarionhub.com/t/how-to-call-shfileoperation-api-to-recursively-delete-files-and-folders/5172/1 "2022-06-03T14:04:52Z")

</div>

Hi all,

In my **Clarion 6.3** application I need to **recursively delete files and folders**.

In Clarion 10 I can use:  
`REMOVE('C:\MyApp\MyData\TempfolderWithSubfolders\*.*',REMOVE:RECURSIVE)`

This isn't supported in Clarion 6.3, so I need to use the **SHFileOperation API** to recursively delete files and folders, but how?

Can somebody help me how to accomplish this with the SHFileOperation API?

Best regards and thank you,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![anon23294430](https://clarionhub.com/user_avatar/clarionhub.com/anon23294430/32/3829_2.png) [@anon23294430](https://clarionhub.com/u/anon23294430)\
**Post date:** [June 3, 2022, 5:49pm UTC](https://clarionhub.com/t/how-to-call-shfileoperation-api-to-recursively-delete-files-and-folders/5172/2 "2022-06-03T17:49:48Z")

</div>

> [@jkuijt](#):
>
> This isn’t supported in Clarion 6.3, so I need to use the **SHFileOperation API** to recursively delete files and folders, but how?

So this api no longer supported [SHFileOperationA function (shellapi.h) - Win32 apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shfileoperationa) and this is what MS are saying we should use. [IFileOperation (shobjidl\_core.h) - Win32 apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifileoperation)

Now you can use  
[RemoveDirectoryA function (fileapi.h) - Win32 apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectorya)

```
BOOL RemoveDirectoryA( [in] LPCSTR lpPathName);
IS_RemoveDirectoryA(*cstring),Bool,Raw,Pascal,Name('RemoveDirectoryA')

```

and  
[DeleteFileA function (fileapi.h) - Win32 apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilea)

```
BOOL DeleteFileA( [in] LPCSTR lpFileName
IS_DeleteFileA(*cstring),Bool, Raw, Pascal,Name('DeleteFileA')

```

These are both Kernel32.dll so have a look in win32.lib using the libmaker to see if they in the WIN32.LIB. If they are then you can prototype them in module(‘winapi’) / End.

But the other thing to consider is what folder traversal method are you going to use?  
[Tree traversal - Wikipedia](https://en.wikipedia.org/wiki/Tree_traversal)

That you will need to do yourself. 😀

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [June 3, 2022, 8:26pm UTC](https://clarionhub.com/t/how-to-call-shfileoperation-api-to-recursively-delete-files-and-folders/5172/3 "2022-06-03T20:26:46Z")

</div>

What is the problem? [Here](https://stackoverflow.com/questions/213392/what-is-the-win32-api-function-to-use-to-delete-a-folder) is an example.  
In C6.3 win32.lib contains SHFileOperationA so you don’t need to link custom lib. Just declare the function and SHFILEOPSTRUCT.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [June 3, 2022, 9:30pm UTC](https://clarionhub.com/t/how-to-call-shfileoperation-api-to-recursively-delete-files-and-folders/5172/4 "2022-06-03T21:30:05Z")

</div>

This example on GitHub uses all Clarion code (e.g. DIRECTORY) to recursively load files into a Queue and display in a LIST. It does a Rename on files but you could change it to do a DeleteFile() or Remove(). You get a Window with a Progress bar.

You can remove the link and call to SHAutoComplete() which is used to auto fill the folder.

> **[GitHub - CarlTBarnes/Zip-FileName-Fixer: Fix File Names by Removing Characters Rejected by...](https://github.com/CarlTBarnes/Zip-FileName-Fixer)**
>
> Fix File Names by Removing Characters Rejected by Zip

Be careful with SHFileOperationA() as sending it bad parameters may delete the wrong stuff, like your project or everything.

---

<div class="post-metadata">

**Author:** ![AbdullahAkilah](https://clarionhub.com/user_avatar/clarionhub.com/abdullahakilah/32/4818_2.png) [@AbdullahAkilah](https://clarionhub.com/u/AbdullahAkilah)\
**Post date:** [June 4, 2022, 1:50am UTC](https://clarionhub.com/t/how-to-call-shfileoperation-api-to-recursively-delete-files-and-folders/5172/5 "2022-06-04T01:50:24Z")

</div>

Why use an API call when you can do it in native clarion statements using Directory() and recursion?

---

<div class="post-metadata">

**Author:** ![jkuijt](https://clarionhub.com/user_avatar/clarionhub.com/jkuijt/32/6168_2.png) [@jkuijt](https://clarionhub.com/u/jkuijt)\
**Post date:** [June 4, 2022, 6:11am UTC](https://clarionhub.com/t/how-to-call-shfileoperation-api-to-recursively-delete-files-and-folders/5172/6 "2022-06-04T06:11:01Z")

</div>

Thank you all!

Best regards  
Jeffrey

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [June 4, 2022, 5:18pm UTC](https://clarionhub.com/t/how-to-call-shfileoperation-api-to-recursively-delete-files-and-folders/5172/7 "2022-06-04T17:18:39Z")

</div>

Sometimes it’s nice to be able to move to the recycle bin and/or see progress.

REMOVE() does support recursion. Not sure when that feature was added, but it wasn’t there when I needed it. 🙂
