How to get part from the full path in C #?

I have a full path as shown below.

C:\Users\Ronny\Desktop\Sources\Danny\kawas\trunk\csharp\ImportME\XukMe\bin\Debug\DannyGoXuk.DTDs.xhtml-math-svg-flat.dtd

How can I get a DTD part from this part?

Required Conclusion:

C:\Users\Ronny\Desktop\Sources\Danny\kawas\trunk\csharp\ImportME\XukMe\bin\Debug‌​\DannyGoXuk.DTDs

Can I use methods Stringfor this?
If so, how to get it?

+5
source share
11 answers

Edit: Please carefully read the OPs question and all its comments before releasing this. The question of the name of the OPs is NOT EXACTLY what she wanted. My answer gave her what she needed to solve her problem. That is why she voted for the answer. Yes, Joels’s answer is correct if he specifically answers the title question. But, after reading her comments, you will see that not quite what she was looking for. Thanks.

...

string strFullPath = @"C:\Users\Ronny\Desktop\Sources\Danny\kawas\trunk\csharp\ImportME\XukMe\bin\Debug\DannyGoXuk.DTDs.xhtml-math-svg-flat.dtd";
string strDirName; 
int intLocation, intLength;

intLength = strFullPath.Length;
intLocation = strFullPath.IndexOf("DTDs");

strDirName = strFullPath.Substring(0, intLocation); 

textBox2.Text = strDirName;
+7

System.IO.Path.GetDirectoryName() new DirectoryInfo(path).Parent.Name .


"DTD". "DannyGoXuk.DTDs.xhtml-math-svg-flat.dtd", (.) , "DannyGoXuk\DTDs\xhtml-math-svg-flat.dtd"?

, , , - DTDs:

string path = @"C:\Users\Ronny\Desktop\Sources\Danny\kawas\trunk\csharp\ImportME\XukMe\bin\Debug\DannyGoXuk\DTDs\xhtml-math-svg-flat.dtd";
string[] files = new DirectoryInfo(path).Parent.GetFiles();

Build Type as Embedded resource.

. " ", . . "" " " " " ", ".

+76

System.IO.Path.GetFileName

, . GetDirectoryName , .

, , :

var directoryFullPath = Path.GetDirectoryName(@"C:\DTDs\mydtd.dtd");  // C:\DTDs
var directoryName = Path.GetFileName(directoryFullPath);  // DTDs
+12

Directory, :

Directory.GetParent(path).FullName
+9
System.IO.Path.GetFileName( System.IO.Path.GetDirectoryName( fullPath ) )

, .

C:\windows\system32\user32.dll

system32

, .

+5

:

string dirName = new DirectoryInfo(fullPath).name;
+5

:

System.IO.Path.GetDirectoryName(path);
+2

Path...

Path.GetDirectoryName(myStr);
+2

. GetDirectoryName Path:

System.IO.Path.GetDirectoryName(myPath);
+2

FileInfo...

FileInfo info = new FileInfo(@"C:\Users\Ronny\Desktop\Sources\Danny\kawas\trunk\csharp\ImportME\XukMe\bin\Debug\DannyGoXuk.DTDs.xhtml-math-svg-flat.dtd");
string directoryName = info.Directory.FullName;

.

+2

Path.GetDirectory :

"C:\Users\Ronny\Desktop\Sources\Danny\Kawas\\CSharp\ImportME\XukMe\Bin\Debug"

:

var path = Path.GetDirectoryName(@"C:\Users\Ronny\Desktop\Sources\Danny\kawas\trunk\csharp\ImportME\XukMe\bin\Debug\DannyGoXuk.DTDs.xhtml-math-svg-flat.dtd");

: DTD.

+1

All Articles