RealDocs

UBlueprintPathsLibrary::CollapseRelativeDirectories

function Engine Blueprint Since 4.20
#include "Kismet/BlueprintPathsLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintPure

Description

Eliminates relative ".." pathing by annihilating each ".." segment with the directory adjacent to it, collapsing the path into its resolved form.

Caveats & Gotchas

  • Assumes all slashes have already been converted to '/' — run NormalizeFilename first if the path may still contain backslashes.
  • Returns false if the path contains a ".." that cannot be collapsed (e.g. it would walk above the root), leaving OutPath in an undefined state you should not rely on.

Signature

static bool CollapseRelativeDirectories(const FString& InPath, FString& OutPath)

Parameters

Name Type Description Default
InPath const FString& A fully pathed string, e.g. "BaseDirectory/SomeDirectory/../SomeOtherDirectory/Filename.ext".
OutPath FString& Receives the path with ".." segments resolved against their adjacent directory.

Return Type

bool

Example

Resolve a path with parent directory references C++
FString Collapsed;
bool bOk = UBlueprintPathsLibrary::CollapseRelativeDirectories(TEXT("BaseDirectory/SomeDirectory/../SomeOtherDirectory/Filename.ext"), Collapsed);
// bOk == true, Collapsed == TEXT("BaseDirectory/SomeOtherDirectory/Filename.ext")

Version History

Introduced in: 4.20

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.