How do I delete all files in an Azure File Storage folder?

Took existing answers, fixed some bugs and created an extension method to delete the directory recursively

public static async Task DeleteAllAsync(this ShareDirectoryClient dirClient) {

    await foreach (ShareFileItem item in dirClient.GetFilesAndDirectoriesAsync()) {
        if (item.IsDirectory) {
            var subDir = dirClient.GetSubdirectoryClient(item.Name);
            await subDir.DeleteAllAsync();
        } else {
            await dirClient.DeleteFileAsync(item.Name);
        }
    }

    await dirClient.DeleteAsync();
}

Call it like

var dirClient = shareClient.GetDirectoryClient("test");
await dirClient.DeleteAllAsync();

This recursive version works if you have 'directories' inside your 'directory'

       public void DeleteOutputDirectory()
       {
           var share = _fileClient.GetShareReference(_settings.FileShareName);
           var rootDir = share.GetRootDirectoryReference();

           DeleteDirectory(rootDir.GetDirectoryReference("DirName"));
       }

       private static void DeleteDirectory(CloudFileDirectory directory)
       {
           if (directory.Exists())
           {
               foreach (IListFileItem item in directory.ListFilesAndDirectories())
               {
                   switch (item)
                   {
                       case CloudFile file:
                           file.Delete();
                           break;
                       case CloudFileDirectory dir:
                           DeleteDirectory(dir);
                           break;
                   }
               }

               directory.Delete();
           }
       }

ListFilesAndDirectories can return both files and directories so you get a base class for those two. Then you can check which if the types it is and cast. Note you'll want to track any sub-directories so you can recursively delete the files in those.

var folder = root.GetDirectoryReference("myfolder");

if (folder.Exists())
{
    foreach (var item in folder.ListFilesAndDirectories())
    {         
        if (item.GetType() == typeof(CloudFile))
        {
            CloudFile file = (CloudFile)item;

            // Do whatever
        }

        else if (item.GetType() == typeof(CloudFileDirectory))
        {
            CloudFileDirectory dir = (CloudFileDirectory)item;

            // Do whatever
        }
    }
}