I’m sure someone’s going to advise me to do something different, but for now I’m trying to use the WinAPI to accomplish my goals. I found some good information at Displaying Volume Paths - Win32 apps | Microsoft Docs and hacked something out of that.
MyTestObject.h
#include "Object.h"
#include "MyTestObject.generated.h"
UCLASS(NotPlaceable)
class UMyTestObject : public UObject
{
GENERATED_UCLASS_BODY()
/* Returns an array of strings with available physical drive paths, i.e. A:\ or C:\
No networked/mapped drives */
UFUNCTION(BlueprintPure, meta = (FriendlyName = "Get Drive Paths", Keywords = "Array String Drive Paths"), Category = "MyNodes|FileManagement")
static TArray<FString> GetDrivePaths();
};
…and MyTestObject.cpp
#include "MyTestObject.h"
UMyTestObject::UMyTestObject(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
TArray<FString> UMyTestObject::GetDrivePaths()
{
TArray<FString> DrivePaths;
uint32 CharCount = 0;
WCHAR DeviceName[MAX_PATH] = L"";
uint32 Error = ERROR_SUCCESS;
HANDLE FindHandle = INVALID_HANDLE_VALUE;
BOOL Found = false;
size_t Index = 0;
BOOL Success = false;
WCHAR VolumeName[MAX_PATH] = TEXT("");
// Enumerate all volumes in the system
FindHandle = FindFirstVolumeW(VolumeName, ARRAYSIZE(VolumeName));
if (FindHandle == INVALID_HANDLE_VALUE)
{
Error = GetLastError();
// wprintf(L"FindFirstVolumeW failed with error code %d", Error);
DrivePaths.Empty();
return DrivePaths;
}
do
{
// Skip the \\?\\ prefix and remove the trailing backslash
Index = wcslen(VolumeName) - 1;
(to be continued)