This demo mainly involves obtaining the file name, directory, extension, and merging the two characters into the path. csdn's question about getting the directory at the specified layer
Http://topic.csdn.net/u/20100201/17/958c272f-2ab7-46c2-9592-afef1ec0ea28.html)
Demo download: http://pan.baidu.com/share/link? Consumer id = 446013 & UK = 3627406265
Main Application Methods:
1. getextension: Get the extension of the specified path string
2. getpathroot: Get the root directory of the specified path string
3. getfilename: get the file name and extension of the specified string
4. getfilenamewithoutextension: returns the file name of a specified path string without an extension.
5. getdirectoryname: Get the directory information of the specified path string
5. Combine: merge two path strings
The following code
Private void btngetfullfilename_click (Object sender, eventargs e) {string Path = cbopath. text; string filename = txtfilename. text; // do not use the combine solution // If (path. endswith (@ "\") // {// label3.text = path + filename; //} // else // {// label3.text = path + "\" + filename; //} // combine: combine two path strings label9.text = path. combine (path, filename);} private void btnparentpath_click (Object sender, eventargs e) {directoryinfo di = New directoryinfo (cbopath. Text); If (Di. parent! = NULL) {label9.text = di. parent. fullname;} else {label9.text = "already the root directory";} // do not use the parent solution // string Path = cbopath. text; // If (path. endswith (@ "\") // {// Path = path. substring (0, path. length-1); // label3.text = path. substring (0, path. lastindexof (@ "\") + 1); //} // else // {// label3.text = path. substring (0, path. lastindexof (@ "\") + 1); //} private void button#click (Object sender, eventargs e) {string STR = @ "C: \ Documents and Settings \ ty \ Desktop \ Engineering Test \ tttttttt \ KKK \ vv.txt "; // After the string is separated by" \ ", the length is-6, that is, the sixth item from the back to the front, the file name occupies one item, and the sixth item is actually the fifth-level directory label11.text = Str. split ('\') [Str. split ('\\'). length-6];}
The running result is as follows: