c# - How can I get the last folder from a path string? -
i have directory looks this:
c:\users\me\projects\
in application, append path given project name:
c:\users\me\projects\myproject
after, want able pass method. inside method use project name. best way parse path string last folder name?
i know work-around pass path , project name function, hoping limit 1 parameter.
you can do:
string dirname = new directoryinfo(@"c:\users\me\projects\myproject\").name;
or use path.getfilename
(with bit of hack):
string dirname2 = path.getfilename( @"c:\users\me\projects\myproject".trimend(path.directoryseparatorchar));
path.getfilename
returns file name path, if path terminating \
return empty string, why have used trimend(path.directoryseparatorchar)
Comments
Post a Comment