You can find the root directory of a directory in C# using the Path.GetPathRoot()
method. This method returns the root directory of a path, which is the first directory of a path that is followed by a directory separator character. Here's an example of how to use it:
main.cs198 chars7 lines
In this example, we use the Path.GetPathRoot()
method to find the root directory of a path string "C:/Users/username/Documents/folder/file.txt"
. The method returns the root directory "C:/"
, which is then printed to the console.
gistlibby LogSnag