Forum > Beginners

SysUtils.ExtractFileExt

(1/2) > >>

Aqdam1978@yahoo.com:
Hello,

There is a bug in the ExtractFileExt function, when a file's name is null, this function returns null, for example:

SysUtils.ExtractFileExt('sample.txt') returns ".txt" however, SysUtils.ExtractFileExt('.txt') returns ""

Is there any other routine to extract filename's extension?

Thanks,

trev:

--- Quote from: Aqdam1978@yahoo.com on September 14, 2021, 04:48:34 am ---SysUtils.ExtractFileExt('sample.txt') returns ".txt" however, SysUtils.ExtractFileExt('.txt') returns ""
--- End quote ---

Which is correct because the filename ".txt" has no file extension. In UNIX and UNIX-like circles it is a hidden file.

Aqdam1978@yahoo.com:
It's not correct! file name format should be like "name.ext"

if you try SysUtils.ExtractFileName('.txt') it will return null too!
so both functions return null.

SysUtils.ExtractFileExt('.txt') retuns ""
SysUtils.ExtractFileName('.txt') retuns ""

I expect to get ".txt" when I am calling the SysUtils.ExtractFileExt('.txt')

devEric69:

--- Quote from: Aqdam1978@yahoo.com on September 15, 2021, 04:31:26 pm ---if you try SysUtils.ExtractFileName('.txt') it will return null too!

--- End quote ---

I agree: in Linux, if '.txt' is the full name (so, without\no extension in this case) of a hidden file, SysUtils.ExtractFileName('.txt') should return the whole '.txt', imo (not null). No?

Kays:

--- Quote from: Aqdam1978@yahoo.com on September 15, 2021, 04:31:26 pm ---if you try SysUtils.ExtractFileName('.txt') it will return null too!
--- End quote ---
No, it doesn’t, unless you’ve altered allowDirectorySeparators/allowDriveSeparators.

As trev already wrote, extractFileExt('.txt') correctly returns an empty string. The term file extension implies you’re extending a name. What “name” would you like to extend in .txt? Exactly, there is no name. On no OS in the world an empty string would constitute a valid file name, thus the entire string '.txt' is the file name and there is no file name extension.

Navigation

[0] Message Index

[#] Next page

Go to full version