Home  |  Delphi .net Home  |  System.IO.Path  |  HasExtension Method
  
HasExtension  
Method  
Returns True if the specified Path string includes a file name with extension
Path Class
System.IO NameSpace
CF1.  Function HasExtension ( PathString : String ) : Boolean; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
If the PathString contains a file name that has an extension, such as '.txt' or 'exe', then true is returned, otherwisefalse is returned.
Microsoft MSDN Links
System.IO
System.IO.Path
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Getting the extension of files with an without extensions
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  PathString : String;

begin
  PathString := 'C:\DelphiBasics.txt';

  if System.IO.Path.HasExtension(PathString)
  then Console.WriteLine('"{0}" has extension "{1}"',
                         PathString,
                         System.IO.Path.GetExtension(PathString))
  else Console.WriteLine('"{0}" has no extension',
                         PathString);

  PathString := 'C:\DelphiBasics';

  if System.IO.Path.HasExtension(PathString)
  then Console.WriteLine('"{0}" has extension "{1}"',
                         PathString,
                         System.IO.Path.GetExtension(PathString))
  else Console.WriteLine('"{0}" has no extension',
                         PathString);

  Console.Readline;
end.
   "C:\DelphiBasics.txt" has extension ".txt"
   "C:\DelphiBasics" has no extension
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author