How to call SHFileOperation API to recursively delete files and folders

Hi all,

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

In Clarion 10 I can use:

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,

So this api no longer supported SHFileOperationA function (shellapi.h) - Win32 apps | Microsoft Docs and this is what MS are saying we should use. IFileOperation (shobjidl_core.h) - Win32 apps | Microsoft Docs

Now you can use
RemoveDirectoryA function (fileapi.h) - Win32 apps | Microsoft Docs

BOOL RemoveDirectoryA( [in] LPCSTR lpPathName);

DeleteFileA function (fileapi.h) - Win32 apps | Microsoft Docs

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

That you will need to do yourself. :grinning:

What is the problem? Here 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.

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.

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

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

Thank you all!

Best regards

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. :slight_smile: