Delphi File name Function-path, name, subdirectory, drive, extension

Source: Internet
Author: User

File name function

The filename function can manipulate the file name, subdirectory, drive, extension, and so on. The following table lists these functions and their functions.

Function description

Expandfilename ()//return the full path of the file (with drive, path)

Extractfileext ()//Extract the extension from the file name

Extractfilename ()//extract the file name without a path from the file name

Extractfilepath ()//Extract the pathname from the file name

Extractfiledir ()//Extract the directory name from the file name

Extractfiledrive ()//extract the drive name from the file name

Changefileext ()//change the file's extension

Expanduncfilename ()//returns the full path to the file that contains the network drive

Extractrelativepath ()//Extract relative path information from the file name

Extractshortpathname ()//Convert file name to DOS 8 3 format

Matchesmask ()//check to see if the file matches the specified file name format

Extractfilepath (filename:string)//The function returns the path name with the trailing character always "\"

Extractfiledir (filename:string)//The function also returns the pathname, but does not include the trailing character "\" unless the path returned is the root directory.

Here's a description of these functions:

⑴expandfilename ()

Prototype: extern package ansistring __fastcall expandfilename (const ansistring FileName);

Function: Returns the full path of the file (with drive, path)

Parameter: FileName: file name to process

Example: ShowMessage (Expandfilename (Application->exename));//Display your program file name, such as C:\MyBCB\Sample1.EXE

⑵extractfileext ()

Prototype: extern package ansistring __fastcall extractfileext (const ansistring FileName);

Function: Extract the extension from the file name

Parameter: FileName: file name to process (full path)

Example: ShowMessage (Extractfileext (Application->exename));//display ". exe"

⑶extractfilename ()

Prototype: extern package ansistring __fastcall extractfilename (const ansistring FileName);

Function: Extract file name without path from file name

Parameter: FileName: file name to process

Example: ShowMessage (Extractfileext ("C:\\winnt\\sol"). EXE ");//Display" SOL. " EXE "

⑷extractfilepath ()

Prototype: extern package ansistring __fastcall extractfilepath (const ansistring FileName);

Function: Extracting path names from file names

Parameter: FileName: file name to process

Example: ShowMessage (Extractfilepath ("Winnt\\sol"). EXE "));//display" winnt\ "

⑸extractfiledir ()

Prototype: extern package ansistring __fastcall extractfiledir (const ansistring FileName);

Function: Extract the directory name from the file name (unlike the previous function, excluding the last "\")

Parameter: FileName: file name to process

Example: ShowMessage (Extractfiledir ("Winnt\\sol"). EXE ");//Display" Winnt ", notice the difference from the previous function

⑹extractfiledrive ()

Prototype: extern package ansistring __fastcall extractfiledrive (const ansistring FileName);

Function: Extract the drive name from the file name

Parameter: FileName: file name to process

Example: ShowMessage (extractfiledrive ("C:\\winnt\\sol"). EXE "));//display" C: "

⑺changefileext ()

Prototype: extern package system::ansistring __fastcall changefileext (const system::ansistring FileName, const System:: Ansistring Extension);

Function: Change the file name extension, not to rename the real file, just the file name of the string processing

Parameter: FileName: Name of the file to rename, Extension: New extension

Example: ShowMessage (Changefileext ("C:\\winnt\\sol"). EXE ",". OOO ");//Display" C:\winnt\SOL. " OOO "

⑻expanduncfilename ()

Prototype: extern package ansistring __fastcall expanduncfilename (const ansistring FileName);

Function: Returns the full path of the file containing the network drive, in the format: \ \ machine name \ share name \ file name

Parameter: FileName: file name to process

Example: ShowMessage (Expanduncfilename ("F:\\winnt\\sol"). EXE "), or/* If f: is a mapped network drive \\NT40\WINNT, the \\NT40\WINNT\SOL is displayed. EXE "* *

⑼extractrelativepath ()

Prototype: extern package ansistring __fastcall extractrelativepath (const ansistring BaseName, const ansistring destname);

Function: Extracts relative path information from the file name, such as ".. \SSS\SS.ASD "This form

Parameters: BaseName: Reference file name; Destname: Target file name

Example: ShowMessage (Extractrelativepath ("d:\\source\\c\\1.123", "d:\\source\\asm\\dz.asm");/* show ". \asm\dz.asm "* *

⑽extractshortpathname ()

Prototype: extern package ansistring __fastcall extractshortpathname (const ansistring FileName);

Function: Convert file name to DOS 8, 3 format

Parameter: FileName: file name to process

Example: ShowMessage (Extractshortpathname ("E:\\program files\\dual Wheel mouse\\4dmain.exe");/* display "e:\progra~1\dualwh~1\ 4dmain.exe "* *

⑾matchesmask ()

Prototype: extern package bool __fastcall matchesmask (const ansistring Filename, const ansistring Mask);

Function: Checks whether the file matches the specified file name format

Parameters: FileName: file name to be processed; Mask: File name format, wildcard characters supported

Example: ShowMessage (Matchesmask ("Lxf.exe", "*.") X?)); /Show "true"

Delphi File name Function-path, name, subdirectory, drive, extension

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.