c# - Getting File name from the String -
could me finding file name string. have 1 string of content "c:\xxxx\xxxx\xxxx\abc.pdf". want file name ie. abc.pdf. how using string functions?
use path.getfilename
:
string full = @"c:\xxxx\xxxx\xxxx\abc.pdf"; string file = path.getfilename(full); console.writeline(file); // abc.pdf
note assumes last part of name file - doesn't check. if gave "c:\windows\system32" claim filename of system32, though that's directory. (passing in "c:\windows\system32\" return empty string, however.) can use file.exists
check file exists and file rather directory if help.
this method doesn't check other elements in directory hierarchy exist - pass in "c:\foo\bar\baz.txt" , return baz.txt if foo , bar don't exist.
Comments
Post a Comment