Last active
August 31, 2018 20:26
-
-
Save nosajhpled/b7e2cc531245fd2fa97a772b643e4500 to your computer and use it in GitHub Desktop.
C# – Extract filename from a full path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Over the years extracting the filename from a full path has always been a pain for me. Working with C#, I discovered a one line, easy to use, solution. | |
FileName = FileName.Split('\\')[FileName.Split('\\').Count() - 1]; | |
Filename = “c:\TextFile.txt” | |
Will return: | |
“TextFile.txt” | |
And | |
FileName = (FileName.Split('\\')[FileName.Split('\\').Count() - 1]).Split(',')[0]; | |
Filename = “c:\TextFile.txt” | |
Will return: | |
“TextFile” |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment