📉Files - NKS0023

Use Filesystem.NeutralizePath()

This analyzer provides the following strings:

ContextString

Error List

Caller uses Path.GetFullPath instead of Filesystem.NeutralizePath()

Suggestion Box

Use Filesystem.NeutralizePath() instead of Path.GetFullPath

Description

Filesystem.NeutralizePath() neutralizes the provided path to its absolute correct path, but also gives a path separated by the platform-agnostic path separator.

Extended Description

This code analyzer detects the usage of GetFullPath from the standard Path class found in the System.IO namespace.

While Path.GetFullPath() operates on the executable project directory, it doesn't represent the state of the current working directory because the UESH shell doesn't use the built-in current working directory property.

NeutralizePath() had to be made to not only solve this problem, but also gives you a unified path that has folder names spearated by the platform-agnostic path separator.

Analysis Comparison

To get a brief insight about how this analyzer works, compare the two code blocks shown to you below:

Before the fix

Somewhere in your mod code...
public static void MyFunction()
{
    string path = Path.GetFullPath("test.txt");
}

After the fix

Somewhere in your mod code...
public static void MyFunction()
{
    string path = FilesystemTools.NeutralizePath("test.txt");
}

Suppression

You can suppress this suggestion by including it in the appropriate place, whichever is convenient.

For more information about how to suppress any warning issued by the Nitrocid analyzer, visit the below page:

Recommendation

We recommend that every caller which use this function use the recommended abovementioned method.

Last updated