delphifiremonkeyvcldelphi-12-athens

Should I use FileExists(Path) or TFile.Exists(Path) in Delphi?


I'm always working on the latest Delphi and so I have TFile.Exists(Path) available to me, but currently at my company, all of our code uses the older FileExists(Path) method.

What are the differences between FileExists and TFile.Exists in Delphi, and which should I use?

I know they both come from different units as well:

FileExists(Path):

uses SysUtils;

if FileExists(Path) then
  // ...

TFile.Exists(Path):

uses System.IOUtils;

if TFile.Exists(Path) then
  // ...


I personally prefer the TFile.Exists(Path) method. So I'm wondering if I should just go ahead and replace all of the FileExists(Path) code with the newer TFile.Exists(Path) method.

Most of our apps are FMX, but we do have a couple that are still VCL (although they will eventually become FMX also).


Solution

  • The implementation of TFile.Exists is:

    class function TFile.Exists(const Path: string; FollowLink: Boolean = True): Boolean;
    begin
      Result := FileExists(Path, FollowLink);
    end;
    

    So the two functions are indeed completely interchangeable.