Here are some representative operations using methods from the Path class for handling file paths.
1. Combine Folder Name and File Name
1-1. Combining Folder Name and File Name
A backslash “\” is automatically added at the joining part. If there is already a backslash “\” , it will not be added again and will be combined as is.
Example: Path.Combine("C:\Users\test", "file.txt")
Message Box Input Example:
Output Example:
1-2. Combining Multiple Folder Names and File Name (More Than One Folder Name)
The backslash ("") is automatically added at the joining parts. If there is already a backslash, it will not be added again and will be combined as is.
Example: Path.Combine("C:\Users\test", "abc", "file.txt")
Message Box Input Example:
Output Example:
2. Extract File Name from Full Path
2-1. Extract File Name with Extension
Example: Path.GetFileName("C:\Users\test\file.txt")
Message Box Input Example:
Output Example:
2-2. Extract File Name Without Extension
Example: Path.GetFileNameWithoutExtension("C:\Users\test\file.txt")
Message Box Input Example:
Output Example:
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article