File Path-related string operations

Source: Internet
Author: User
Uses httpapp, masks; Procedure tform1.button1click (Sender: tobject); var SS, S: string; begin // extract the string SS: = application. exename; showmessage (SS); // C: \ Documents ents and Settings \ WY \ My Documents ents \ rad studio \ projects \ project1.exe // path S: = extractfilepath (SS ); showmessage (s); // C: \ Documents ents and Settings \ WY \ My Documents ents \ rad studio \ projects \ // folder S: = extractfiledir (SS ); showmessage (s); // C: \ Documents And Settings \ WY \ My Documents ents \ rad studio \ projects // Logical Disk S: = extractfiledrive (SS); showmessage (s); // C: // file name s: = extractfilename (SS); showmessage (s); // project1.exe // file extension S: = extractfileext (SS); showmessage (s );//. EXE // relative path S: = extractrelativepath ('C: \ Documents and Settings \ WY \ My Documents \ ', SS); showmessage (s ); // rad studio \ projects \ project1.exe // short file name s under DOS: = extract?pathname (SS ); Showmessage (s); // C: \ w.e ~ 1 \ WY \ mydocu ~ 1 \ radstu ~ 1 \ projects \ project1.exe // convert to the Unix path format. Uses httpapp S: = dospathtounixpath (SS); showmessage (s); // C: /Documents and Settings/WY/My Documents documents/rad studio/projects/project1.exe // convert the Unix path format to window format, which is the inverse operation s of dospathtounixpath: = expanduncfilename (dospathtounixpath (SS); showmessage (s); // C: \ Documents and Settings \ WY \ My Documents \ rad studio \ projects \ project1.exe // remove the end path separator S: = excludetrailingpathdelimiter (extractfilepath (SS); showmessage (s ); // C: \ Documents ents and Settings \ WY \ My Documents ents \ rad studio \ projects // remove the path separator at the end, just call: excludetrailingpathdelimiter s: = excludetrailingbackslash (extractfilepath (SS); showmessage (s); // C: \ Documents and Settings \ WY \ My Documents ents \ rad studio \ projects // change the extension, the file is not modified, but the string S: = changefileext (SS ,'. bak '); showmessage (s); // C: \ Documents ents and Settings \ WY \ My Documents ents \ rad studio \ projects \ project1.bak // change file path: s: = changefilepath (SS, 'c: \ Temp '); showmessage (s); // C: \ temp \ project1.exe // determines whether the first character is a path separator: ispathdelimiter (SS, 3); // return true // determine whether the suffix is exe; uses masks matchesmask (SS ,'*. EXE '); // returns trueend;
 
   
 // Decompose processpath (uses filectrl required) var S, P, F: string; D: Char; begin S: = paramstr (0); showmessage (s); // C: \ Documents and Settings \ WY \ My Documents ents \ rad studio \ projects \ project1.exe processpath (S, D, P, f); showmessage (d); // C showmessage (P ); // \ Documents ents and Settings \ WY \ My Documents ents \ rad studio \ projects showmessage (f); // project1.exeend;
  
   
 // Compress and display minimizename (uses filectrl required) var S: string; begin S: = paramstr (0); s: = minimizename (S, self. canvas, 100); showmessage (s); // C :\... \ project1.exeend;
  
   
 

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.