UEditorAssetLibrary::DoesDirectoryHaveAssets returns false even when folder has assets

Hi everyone,

I’m currently working on an Editor Utility module in Unreal Engine 5.5, and I’m trying to detect whether a specific content folder has assets in it.

I’m using the following API:

UFUNCTION (BlueprintCallable, Category="Editor Scripting | Asset")  
static bool DoesDirectoryHaveAssets  
(  
    const FString & DirectoryPath,  
    bool bRecursive  
)  

However, even though the folder I’m checking (e.g. /Game/MyFolder) does contain assets, the function still returns false.

void FSuperManagerModule::OnDeleteEmptyFolderButtonClicked() {
	FixUpRedirectors();
	TArray<FString> FolderPathArray = UEditorAssetLibrary::ListAssets(FolderPaths[0], true, true);
	uint32 Counter = 0;

	FString EmptyFolderPathNames;
	TArray<FString> EmptyFolderPathArray;
	for (const FString& FolderPath : FolderPathArray) {
		if (FolderPath.Contains(TEXT("Developers")) ||
			FolderPath.Contains(TEXT("Collections")) ||
			FolderPath.Contains(TEXT("__ExternalActors__")) ||
			FolderPath.Contains(TEXT("__ExternalObjects__")) 
			) continue;

		if (!UEditorAssetLibrary::DoesDirectoryExist(FolderPath)) continue;
		//DebugHeader::Print(5.f, FColor::Green, FolderPath );
		if (!UEditorAssetLibrary::DoesDirectoryHaveAssets(FolderPath)) {

			EmptyFolderPathNames.Append(FolderPath);
			EmptyFolderPathNames.Append("\n");

			EmptyFolderPathArray.Add(FolderPath);
		}
	}

	if (EmptyFolderPathArray.Num() == 0) {
		DebugHeader::ShowMessageDialog(EAppMsgType::Ok, TEXT("No empty folder found under select folder"), false);
		return;
	}

	EAppReturnType::Type Result =
		DebugHeader::ShowMessageDialog(EAppMsgType::OkCancel, TEXT("Empty folder found in :\n") + EmptyFolderPathNames + TEXT("Would you like to delete them"), false);
	if (Result == EAppReturnType::Cancel) return;

	for (const FString& EmptyFolder : EmptyFolderPathArray) {
		if (UEditorAssetLibrary::DeleteDirectory(EmptyFolder)) {
			++Counter;
		}
		else {
			DebugHeader::PrintLog(TEXT("Failed delete ") + EmptyFolder);
		}
	}
	DebugHeader::ShowMessageDialog(EAppMsgType::Ok, TEXT("Successfully delete") + FString::FromInt(Counter) + TEXT(""), false);
}

Totally same as the course,but.


As you can see, NewFolder/NewFolder1 is not Empty, however the ‘DoesDirectoryHaveAssets’ return false.

I want to know why and how to fix this.

1 Like

I had the same problem.
If you run on debug mode and trace the stack, you will see unreadable path string which passed to return AssetRegistryModule.Get().HasAssets(*DirectoryPackageName, bRecursive); Line1466,EditorAssetSubsystem.cpp;
So I guess maybe somewhere doesn’t handle encoding correctly. You can try setting up “Global language support is available using Unicode UTF8” in Windows region settings and try again.Hope it helps!
In Chinese:在Windows区域-管理-更改系统区域设置-Beta版:使用Unicode UTF-8提供全球语言支持-勾选-重启

1 Like