aa1
6 years agoContributor
Deleting folders does not work
Hi, I am trying to delete a folder from my local directory. The following piece of code seems to run for the first two or one folders and then it crashes. I cannot seem to understand what is wrong. Can any one point out what is wrong?
var foldersToDelete,aFolder; foldersToDelete = aqFileSystem.FindFolders(filePath,"*_files"); Delay(20000); if (foldersToDelete.Count > 0) { while (foldersToDelete.HasNext()) { aFolder = foldersToDelete.Next(); aqFileSystem.DeleteFolder(aFolder.Path,true); Log.Message("Deleted Folder: " + aFolder.Path); } } else { Log.Message("No folders found to delete"); }
It fails at this line if (foldersToDelete.Count > 0). The error I get is this: JScript runtime error. Object required.
Thank you in advance.
aa
I think the problem is that if FindFolders doesn't find anything, it doesn't return a collection at all but a "null" value. The code you shold use is, instead of
if (foldersToDelete.Count > 0)
replace with
if (foldersToDelete != null)
Hi,
I think Robert is correct. .Count is not a property of the result returned by .FindFolders() method. Refer to the code sample provided in the documentation for this method.