{"id":74299,"date":"2022-10-05T08:01:22","date_gmt":"2022-10-05T06:01:22","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=74299"},"modified":"2023-11-13T09:36:02","modified_gmt":"2023-11-13T08:36:02","slug":"csharp-path-class","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-path-class\/","title":{"rendered":"Path Class in C#"},"content":{"rendered":"<p>When we want to perform operations on path strings containing file or directory path information, the best choice is to call the built-in C# Path Class methods. This class comes under the <code>System.IO<\/code> namespace and <code>System.Runtime.dll<\/code> assembly. In this article, we are going to show you the most important operations to simplify path string manipulations.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-classes-struct-record\/PathClassCsharp\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s start.<\/p>\n<h2>What Is a Path String?<\/h2>\n<p>We use a path string to define the file or directory location on a disk, in memory, or on a device.\u00a0 Each platform determines the path format.<\/p>\n<p>Let&#8217;s take a look at some examples for path strings:<\/p>\n<ul>\n<li>&#8220;c:\\\\MyDir\\\\MyFile.txt&#8221; in C# (Windows).<span style=\"color: #ff0000;\"><i>\u00a0<\/i><\/span><\/li>\n<li>&#8220;\/MyDir\/MyFile.txt&#8221; in C# (Linux).<\/li>\n<li>&#8220;\\\\MyDir\\\\MySubdir&#8221; in C# (Windows).<span style=\"color: #ff0000;\"><i>\u00a0<\/i><\/span><\/li>\n<li>&#8220;\/MyDir\/MySubdir&#8221; in C# (Linux).<span style=\"color: #ff0000;\"><i>\u00a0<\/i><\/span><\/li>\n<\/ul>\n<p>A path can contain absolute or relative location information. Absolute paths fully specify a location. Relative paths use the current location as the starting point for locating a file.<\/p>\n<h2>Directory, Path, and Volume Separator Characters<\/h2>\n<p>The current platform determines the set of characters for separating the directory, path, volume elements, and the set of characters that we cannot use when specifying paths. Because of these differences, the fields of the Path class as well as the exact behavior of some members of the Path class are platform-dependent.<\/p>\n<p><code>DirectorySeparatorChar<\/code> field provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public char DirectorySeparatorChar() \r\n{ \r\n     var result = Path.DirectorySeparatorChar;\r\n     Console.WriteLine($\"Path.DirectorySeparatorChar: '{result}'\");\r\n \r\n     return result; \r\n}<\/pre>\n<p>In this case, when we run the example the result is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Path.DirectorySeparatorChar: '\\' \/\/ Windows system output\r\nPath.DirectorySeparatorChar: '\/' \/\/ Linux system output<\/pre>\n<p>In Windows, there is an alternative Directory separator <code>'\/'<\/code>, but in Linux the alternative separator is the same as the <code>DirectorySeparatorChar<\/code>. <span style=\"font-weight: 400;\">We can obtain the alternative separator by using the <code>AltDirectorySeparatorChar<\/code> field from the Path class:\u00a0<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public char AltDirectorySeparatorChar() \r\n{ \r\n     var result = Path.AltDirectorySeparatorChar;\r\n     Console.WriteLine($\"Path.AltDirectorySeparatorChar: '{result}'\");\r\n\r\n     return result; \r\n}<\/pre>\n<p>The output:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Path.AltDirectorySeparatorChar: '\/' \/\/ Windows system output\r\nPath.AltDirectorySeparatorChar: '\/' \/\/ Linux system output\r\n<\/pre>\n<p>If we use the <code>PathSeparator<\/code> field, we obtain the platform-specific separator character used to separate path strings in environment variables:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public char PathSeparator() \r\n{ \r\n     var result = Path.PathSeparator; \r\n     Console.WriteLine($\"Path.PathSeparator: '{result}'\");\r\n\r\n     return result; \r\n}<\/pre>\n<p>The path separator also differs from Windows to Linux:\u00a0<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Path.PathSeparator: ';' \/\/Windows system output \r\nPath.PathSeparator: ':' \/\/Linux system output<\/pre>\n<p><code>VolumeSeparatorChar<\/code> provides a platform-specific volume separator character:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public char VolumeSeparatorChar()\r\n{ \r\n     var result = Path.VolumeSeparatorChar;\r\n     Console.WriteLine($\"Path.VolumeSeparatorChar: '{result}'\");\r\n \r\n     return result; \r\n}<\/pre>\n<p>It differs from Windows to Linux as well:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Path.VolumeSeparatorChar: ':' \/\/Windows system output \r\nPath.VolumeSeparatorChar: '\/' \/\/Linux system output<\/pre>\n<h2>How to Get the Invalid Path Characters?<\/h2>\n<p>If we want to get\u00a0 an array containing the characters that are not allowed in path names, we can use the\u00a0 <code>GetInvalidPathChars<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public char[] GetInvalidPathChars()\r\n{\r\n     var result = $\"Path.GetInvalidPathChars:\";\r\n     var invalidChars = Path.GetInvalidPathChars();       \r\n     Console.WriteLine(result);\r\n            \r\n     foreach (var item in invalidChars)\r\n     {\r\n          Console.Write($\"{item} \");\r\n     }            \r\n     Console.WriteLine();\r\n            \r\n     return invalidChars;\r\n}<\/pre>\n<p>The <code>GetInvalidPathChars<\/code> method returns the invalid path characters and we store them in the <code>invalidChars<\/code> array variable. Then, we iterate over the<code>invalidChars<\/code> array to write the content in the console. The output is different if we run the code in a Windows system or a Linux system.<\/p>\n<h2>Ends in Directory Separator<\/h2>\n<p>The <code>EndsInDirectorySeparator<\/code> method returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public bool EndsInDirectorySeparator(ReadOnlySpan&lt;Char&gt; filePath)\r\n{\r\n     var result = Path.EndsInDirectorySeparator(filePath);            \r\n     Console.WriteLine($\"EndsInDirectorySeparator('{filePath.ToString()}') returns '{result.ToString()}'\");\r\n            \r\n     return result;\r\n}<\/pre>\n<div class=\"memberNameHolder\">\n<p>This method receives the <code>filePath<\/code> parameter of the <code>ReadOnlySpan&lt;Char&gt;<\/code> type, and returns a bool <code>result<\/code> variable, confirming whether the given string path ends in a directory separator. It also has another overload accepting the <code>string<\/code> parameter instead of <code>ReadOnlySpan&lt;char&gt;<\/code>.<\/p>\n<\/div>\n<h2>Get or Change Path Extension<\/h2>\n<p>The <code>GetExtension<\/code> method returns the extension (including the &#8220;.&#8221;) of the specified path string:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string GetExtension(string fileName)\r\n{\r\n     var extensionString = Path.GetExtension(fileName);            \r\n     Console.WriteLine($\"GetExtension('{fileName}') returns '{extensionString}'\");\r\n            \r\n     return extensionString;\r\n}<\/pre>\n<p>In this case, we declare a path string <code>fileName<\/code> variable and invoke the <code>GetExtension<\/code> method which retrieves the <code>extensionString<\/code> variable.\u00a0<\/p>\n<p>If we want to change the path string extension, we can invoke the <code>ChangeExtension<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string ChangeExtension(string path, string newExtension)\r\n{            \r\n     var result = Path.ChangeExtension(path, newExtension);            \r\n     Console.WriteLine($\"ChangeExtension({path}, '.old') returns '{result}'\");\r\n            \r\n     return result;\r\n}<\/pre>\n<p>We invoke the <code>ChangeExtension<\/code> method to change the path string extension from, for example <code>.com<\/code>, to a new value <code>.old<\/code>. Additionally, we store the new path in the <code>result<\/code> variable to print it in the console.\u00a0<\/p>\n<h2>Combine Strings Into a Path<\/h2>\n<p>We can combine two strings into a path by calling the <code>Combine<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string Combine(string path1, string path2)\r\n{\r\n     var combination = Path.Combine(path1, path2);            \r\n     Console.WriteLine($\"When you combine '{path1}' and '{path2}', the result is: {Environment.NewLine}'{combination}'\");\r\n\r\n     return combination;\r\n}<\/pre>\n<p>Also with the <code>Combine<\/code> method, we can combine three or four strings or even an array of strings into a path string. You can check our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-classes-struct-record\/PathClassCsharp\" target=\"_blank\" rel=\"nofollow noopener\">source code<\/a> for these additional implementations.<\/p>\n<h2>Get Directory Name<\/h2>\n<p>The <code>GetDirectoryName<\/code> method returns the directory information for the specified path:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string GetDirectoryName(string filePath)\r\n{\r\n     var directoryName = Path.GetDirectoryName(filePath);            \r\n     Console.WriteLine($\"GetDirectoryName('{filePath}') returns '{directoryName}'\");\r\n            \r\n     return directoryName;\r\n}<\/pre>\n<p>We call the <code>GetDirectoryname<\/code> method to extract the directory information from <code>filePath<\/code>\u00a0that we accept as a parameter in our <code>GetDirectoryName<\/code> method.<\/p>\n<h2>Get File Name<\/h2>\n<p>When we want to return the file name for a given file path string, we can use the <code>GetFileName<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public ReadOnlySpan&lt;char&gt; GetFileName(ReadOnlySpan&lt;Char&gt; filePath)\r\n{\r\n    ReadOnlySpan&lt;char&gt; fileName = Path.GetFileName(filePath);            \r\n    Console.WriteLine($\"GetFileName('{filePath.ToString()}') returns '{fileName.ToString()}'\");\r\n            \r\n    return fileName;\r\n}<\/pre>\n<h2>Get Full Path String<\/h2>\n<p>When we call the <code>GetFullPath<\/code> method, we use the file or directory as a parameter we want to obtain absolute path information for. This method returns the absolute path for the specified path string:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string GetFullPath(string mydirPath)\r\n{\r\n     var pathResult = Path.GetFullPath(mydirPath);            \r\n     Console.WriteLine($\"GetFullPath('{mydirPath}') returns '{pathResult}'\");\r\n            \r\n     return pathResult;\r\n}<\/pre>\n<p>This method accepts the <code>mydirPath<\/code> string path parameter and returns the absolute path string, which we store it in the <code>pathResult<\/code> variable.\u00a0<\/p>\n<p>The <code>GetFullPath<\/code> method has another definition receiving two parameters <code><span class=\"hljs-title\">GetFullPath<\/span> (<span class=\"hljs-params\"><span class=\"hljs-built_in\">string<\/span> relativepath, <span class=\"hljs-built_in\">string<\/span> basePath<\/span>)<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string GetFullPath(string path, string basePath)\r\n{\r\n     var pathResult = Path.GetFullPath(path, basePath);            \r\n     Console.WriteLine($\"Fully qualified path:\\n {pathResult}\");\r\n            \r\n     return pathResult;\r\n}<\/pre>\n<p>The first parameter is <code>relativepath<\/code> to concatenate to <code>basePath<\/code>. And the second parameter &#8211; <code>basePath<\/code> is the beginning of a fully qualified path.<\/p>\n<h2>Get Path Root<\/h2>\n<p>The <code>GetPathRoot<\/code> method returns the root directory information from the path contained in the specified string variable:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string GetPathRoot(string fullPathString)\r\n{\r\n     var pathRoot = Path.GetPathRoot(fullPathString);            \r\n     Console.WriteLine($\"GetPathRoot('{fullPathString}') returns '{pathRoot}'\");\r\n            \r\n     return pathRoot;\r\n}<\/pre>\n<p>When we pass the <code>fullPathString<\/code> parameter to the <code>GetPathRoot<\/code> method, we obtain the root directory stored in the <code>pathRoot<\/code> string variable.<\/p>\n<h2>Concatenate Path Components<\/h2>\n<p>In the Path Class, there are several built methods to concatenate path components. All of them share the same name <code>TryJoin<\/code> and <code>Join<\/code>, but they receive different parameters.\u00a0<\/p>\n<p>If we declare the path components with <code>ReadOnlySpan&lt;Char&gt;<\/code> variables, we can use the <code>TryJoin<\/code> method. This method concatenates two, three, or four path components into a single path string:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public void TryJoin(ReadOnlySpan&lt;Char&gt; path1, ReadOnlySpan&lt;Char&gt; path2, Span&lt;Char&gt; destination, out Int32 charsWritten)\r\n{\r\n     if (Path.TryJoin(path1, path2, destination, out charsWritten))\r\n        Console.WriteLine($\"Wrote {charsWritten} characters: '{destination.Slice(0, charsWritten).ToString()}'\");\r\n     else\r\n        Console.WriteLine(\"Concatenation operation failed.\");\r\n}<\/pre>\n<p>Here, we declare two path components <code>path1<\/code> and <code>path2<\/code>\u00a0as <code>ReadOnlySpan&lt;Char&gt;<\/code> parameters. We use both parameters with the <code>TryJoin<\/code> method to concatenate them into a single path string. The result of the concatenation is stored inside the <code>destination<\/code> variable.\u00a0The <code>TryJoin<\/code> method also has an <code>out<\/code><code>charsWritten<\/code> parameter. This parameter indicates the number of characters written to the <code>destination<\/code>.\u00a0<\/p>\n<p>Also, it is possible to send two, three, or four path string variables as arguments for obtaining a single path string by using the <code>Join<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string Join(string path1, string path2, string path3)\r\n{\r\n     var result = Path.Join(path1, path2, path3);            \r\n     Console.WriteLine($\"Path.Join: '{result}'\");\r\n            \r\n     return result;\r\n}<\/pre>\n<p>In this case, we store the path components in three string variables <code>path1<\/code>, <code>path2<\/code> and <code>path3<\/code>, and we call the <code>Join<\/code> method to concatenate them into a single path string.\u00a0<\/p>\n<p>Finally, we can concatenate an array of paths into a single path with <code>Join(string[])<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string Join(string[] pathArrayComponents)\r\n{\r\n     var result = Path.Join(pathArrayComponents);            \r\n     Console.WriteLine($\"Path.Join: '{result}'\");\r\n            \r\n     return result;\r\n}  <\/pre>\n<h2>Conclusion<\/h2>\n<p>In this article, we learned how to work with file and directory path information in C#. We saw how to use different members from the Path class to obtain different pieces of information in both Windows and Linux.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we want to perform operations on path strings containing file or directory path information, the best choice is to call the built-in C# Path Class methods. This class comes under the System.IO namespace and System.Runtime.dll assembly. In this article, we are going to show you the most important operations to simplify path string manipulations. [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12],"tags":[1449,1447,1446,1450,95,1445,1448,81],"class_list":["post-74299","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-directory-separator","tag-get-directory-name","tag-get-file-name","tag-invalid-characters-in-path","tag-linux","tag-path-class","tag-path-extension","tag-windows","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Path Class in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, we are going to learn about the Path class in C#. We&#039;ll see how to use different methods from this class with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-path-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Path Class in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, we are going to learn about the Path class in C#. We&#039;ll see how to use different methods from this class with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-path-class\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-05T06:01:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-13T08:36:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-path-class\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-path-class\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"Path Class in C#\",\"datePublished\":\"2022-10-05T06:01:22+00:00\",\"dateModified\":\"2023-11-13T08:36:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-path-class\/\"},\"wordCount\":982,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-path-class\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"Directory separator\",\"Get directory name\",\"Get file name\",\"invalid characters in path\",\"Linux\",\"Path class\",\"path extension\",\"Windows\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-path-class\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-path-class\/\",\"url\":\"https:\/\/code-maze.com\/csharp-path-class\/\",\"name\":\"Path Class in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-path-class\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-path-class\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2022-10-05T06:01:22+00:00\",\"dateModified\":\"2023-11-13T08:36:02+00:00\",\"description\":\"In this article, we are going to learn about the Path class in C#. We'll see how to use different methods from this class with examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-path-class\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-path-class\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-path-class\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-path-class\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Path Class in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Path Class in C# - Code Maze","description":"In this article, we are going to learn about the Path class in C#. We'll see how to use different methods from this class with examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/csharp-path-class\/","og_locale":"en_US","og_type":"article","og_title":"Path Class in C# - Code Maze","og_description":"In this article, we are going to learn about the Path class in C#. We'll see how to use different methods from this class with examples.","og_url":"https:\/\/code-maze.com\/csharp-path-class\/","og_site_name":"Code Maze","article_published_time":"2022-10-05T06:01:22+00:00","article_modified_time":"2023-11-13T08:36:02+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-path-class\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-path-class\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"Path Class in C#","datePublished":"2022-10-05T06:01:22+00:00","dateModified":"2023-11-13T08:36:02+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-path-class\/"},"wordCount":982,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-path-class\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["Directory separator","Get directory name","Get file name","invalid characters in path","Linux","Path class","path extension","Windows"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-path-class\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-path-class\/","url":"https:\/\/code-maze.com\/csharp-path-class\/","name":"Path Class in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-path-class\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-path-class\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2022-10-05T06:01:22+00:00","dateModified":"2023-11-13T08:36:02+00:00","description":"In this article, we are going to learn about the Path class in C#. We'll see how to use different methods from this class with examples.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-path-class\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-path-class\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-path-class\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-path-class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Path Class in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/74299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=74299"}],"version-history":[{"count":6,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/74299\/revisions"}],"predecessor-version":[{"id":101004,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/74299\/revisions\/101004"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=74299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=74299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=74299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}