Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a class for holding a file system path?

Tags:

.net

In the .NET base class library there is a class System.IO.Path for doing common operations on strings representing a file system path. However, what I need is a class that encapsulates a path instead, so I get type-safety and a possibly shorter notation of path operations. I'm thinking of a .NET equivalent of C++ Boost's path class. Does such a class exist?

Update: I'm not necessarily looking for a class that can hold both file and directory paths. However, as a file system path can be used for pointing to both, I find it obvious that same class can be used.

Conclusion: DirectoryInfo and FileInfo come close to what I'm looking for. However, they seem to be intended as a representation of a file or directory, rather than a file or directory path. This makes it difficult to do path operations, such as combining a directory path and a relative file path, so I think I'll write a class that encapsulates a path.

like image 631
Dimitri C. Avatar asked Dec 18 '22 03:12

Dimitri C.


1 Answers

You are looking for the System.IO.DirectoryInfo class.

The DirectoryInfo class derives from the abstract [FileSystemInfo] class and you also have the FileInfo class that describes files.

like image 174
Rune Grimstad Avatar answered Jan 11 '23 23:01

Rune Grimstad