Io obtains the file path and Extension (Demo is provided)

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.