Path
In this page:
Path
The Path class manipulates file path strings without touching the filesystem — combining segments, extracting file names, and getting extensions. Path.Combine builds a correct path for the current operating system, avoiding manual slash handling. Using Path methods instead of string concatenation avoids cross-platform path bugs.
Note: Always use Path.Combine instead of manually concatenating folder names with / or \\.
Example: Path
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
string fullPath = Path.Combine("data", "reports", "summary.txt");
Console.WriteLine(fullPath);
Console.WriteLine(Path.GetFileName(fullPath));
Console.WriteLine(Path.GetExtension(fullPath));
Console.WriteLine(Path.GetFileNameWithoutExtension(fullPath));
}
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: