TDirectory.GetFiles returns %TMP% as one of the files

When I get a list of files using TDirectory.GetFiles
it returns %TMP% as the first file name

Why is that ? It is not a file, it is an environment variable that points to a folder.

I am launching the program from Windows 10 Start.
Click Start then type in the program name to run it

The current working directory is C:\Windows\System32


Uses System.IOUtils;

var
  vFileName  : string;
begin
  for vFileName in TDirectory.GetFiles('c:\windows\system32') do
      Memo1.lines.add (vFileName);
end;

image

Why is %TMP% being returned in the file list ?

Do you get the same for a console program, @scott.hollows ?

( I tried 10.3.3 and 12, console, with a random dir, and with ‘C:\Users\xxxx\AppData\Local\Temp’ which = TMP )

I havent tried a console application yet

Peter Wright sent me some interesting test cases that showed similar issues so its not just me seeing this behaviour

I’ll look into this further in a few days. Based on what Peter and I are seeing it looks like a Delphi bug where %TMP% is incorrectly appearing in the file list, Some files are not appearing when they should, but that might be a separate bug even though it occurs in the same test case

1 Like