private async void tsRemoveEmptyFolders_Click(object sender, EventArgs e)
        {
            if (!HasGottenFolder())
            {
                return;
            }
            Cloud_Elements_API.CloudFile currentRow = null;
            if (!HasCurrentCloudFile(ref currentRow))
            {
                return;
            }
            frmEmptyFolderScanOptions emptyOptions = new frmEmptyFolderScanOptions();

            if (emptyOptions.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }
            ScanOptions = emptyOptions.ScanOptions;

            APIConnector.EndpointMaxRequestsPerSecond = 2;
            CountOfFoldersRemoved = 0;
            StatusMsg("Starting folder scan...");
            await scanForEmptyFolders(ScanOptions, currentRow);

            StatusMsg("Folder scan ended, see test log for results.");
            TestStatusMsg(string.Format("Folders Removed: {0}", CountOfFoldersRemoved));
        }
        private async Task <bool> scanForEmptyFolders(EmptyFolderOptions scanOptions, Cloud_Elements_API.CloudFile currentRow)
        {
            //StatusMsg(string.Format("Scanning folder {0}", currentRow.name));
            Cloud_Elements_API.CloudElementsConnector ViaConnector = APIConnector.Clone();
            bool deletedAnything = false;

            try
            {
                if (currentRow.directory)
                {
                    List <Cloud_Elements_API.CloudFile> ResultList = null;
                    if (currentRow.size > 0)
                    {
                        ResultList = await ViaConnector.ListFolderContents(Cloud_Elements_API.CloudElementsConnector.FileSpecificationType.Path, currentRow.path, chkWithTags.Checked);

                        TestStatusMsg(string.Format("FYI: Folder {1} contains {0} bytes in file(s)", currentRow.size, currentRow.path));

                        for (int i = 0; i < ResultList.Count; i++)
                        {
                            if (ResultList[i].directory)
                            {
                                deletedAnything = await scanForEmptyFolders(scanOptions, ResultList[i]);
                            }
                        }
                    }


                    // if anything was deleted by our recursive calls, we need to re-get the result list!
                    if (deletedAnything)
                    {
                        ResultList = await ViaConnector.ListFolderContents(Cloud_Elements_API.CloudElementsConnector.FileSpecificationType.Path, currentRow.path, chkWithTags.Checked);

                        //TestStatusMsg(string.Format("FYI: Folder {1} now contains {0} bytes", currentRow.size, currentRow.path));
                        if (ResultList.Count > 1)
                        {
                            return(deletedAnything);
                        }
                    }

                    if ((currentRow.size > 0) && (scanOptions.SingleFileOK) && (ResultList.Count == 1) && !ResultList[0].directory)
                    {
                        double fileAge = -1;
                        if (ResultList[0].IsCreatedValid)
                        {
                            fileAge = DateTime.Now.Subtract(ResultList[0].WhenCreated()).TotalHours;
                        }
                        if ((ResultList[0].size <= scanOptions.SingleFileSizeUnder) &&
                            (!scanOptions.SingleFileTagRequired || ResultList[0].HasTags) &&
                            (ResultList[0].IsCreatedValid && (fileAge >= scanOptions.SingleFileAgeInHours)) &&
                            (ResultList[0].path.EndsWith(scanOptions.SingleFileType, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            // single file is ok to ignored (removed message from here)
                        }
                        else
                        {
                            TestStatusMsg(string.Format("Kept {0} - folder contains {1}, {2} bytes; {3:F1} hours old", currentRow.path, ResultList[0].name, ResultList[0].size, fileAge));
                            return(deletedAnything);
                        }
                    }

                    if ((scanOptions.PathCheck) && (currentRow.path.IndexOf(scanOptions.PathMustContain, StringComparison.CurrentCultureIgnoreCase) < 0))
                    {
                        TestStatusMsg(string.Format("Kept {0} - folder path does not contain {1}", currentRow.path, scanOptions.PathMustContain));
                        return(deletedAnything);
                    }

                    TestStatusMsg(string.Format("Deleting {0}; (empty)", currentRow.path));
                    StatusMsg(string.Format("Deleting {0}, size={1}", currentRow.path, Cloud_Elements_API.Tools.SizeInBytesToString(currentRow.size)));
                    deletedAnything = await ViaConnector.DeleteFolder(Cloud_Elements_API.CloudElementsConnector.FileSpecificationType.Path, currentRow.path, false);

                    CountOfFoldersRemoved++;
                }
            }
            catch (Exception exep)
            {
                StatusMsg(string.Format("Problem! {0}", exep));
            }

            ViaConnector.Close();
            return(deletedAnything);
        }