Is there a special "ExtractFileExt" for Linux? lazarus / 32-Linux ---------------------------------------------------------------------- QEnnay · 2021-08-19 22:12 Hi, I need to check if some file extensions are in a select group. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   anExt:=ExtractFileExt(aFile);  With a Linux ".folder" in the middle of a path it returns what looks to be a single "dot", the text in debugger is too small to see exactly. "/home/user/booth/bill.com" works as expected "/home/user/booth/.config/bill/privatefile" does not Sooo,is there a special ExtractFileExt that can handle dot-folders such as the above ".config"? ---------------------------------------------------------------------- Warfley · 2021-08-19 22:39 You could first get the file name using ExtractFileName and call ExtractFileExt on that: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ext := ExtractFileExt(ExtractFileName(Path)); ---------------------------------------------------------------------- El Salvador · 2021-08-20 07:10 Quote"/home/user/booth/.config/bill/privatefile" does notBut this file has no extension. In fact, I just tried and the method returns an empty string. If I use this path "/home/user/booth/.config/bill/privatefile.ext'" instead, it returns ".ext". ---------------------------------------------------------------------- marcov · 2021-08-20 13:15 It is worth reporting it as a bug to have it looked at. No guarantees, but it might be an oversight. ---------------------------------------------------------------------- winni · 2021-08-20 14:07 Quote from: marcov on August 20, 2021, 03:15:50 pmIt is worth reporting it as a bug to have it looked at. No guarantees, but it might be an oversight. If there is no extension then no extension is the result. What is wrong with this? What do you think should be the result? Switch your logic on. Winni ---------------------------------------------------------------------- marcov · 2021-08-20 14:10 Quote from: winni on August 20, 2021, 04:07:47 pmWhat is wrong with this? What do you think should be the result? I might have misread, I thought he meant splitting on the dot in .config. Not returning an empty (or single dot) extension, which is expected. ---------------------------------------------------------------------- PascalDragon · 2021-08-26 13:22 Quote from: winni on August 20, 2021, 04:07:47 pmWhat is wrong with this? What do you think should be the result? The question is whether ExtractFileExt is supposed to take a path or merely a filename. If the later then there is indeed nothing wrong with it, but if it's supposed to take a path then the result for the path /home/user/booth/.config/bill/privatefile as posted by QEnnay is wrong as ExtractFileExt will return .config/bill/privatefile instead of an empty string. ---------------------------------------------------------------------- Bart · 2021-08-26 19:44 ExtractFileExt is defined in rtl/objpas/sysutils/fina.inc and is OS independant. The algorithm will stop when it finds either a dot or a directoryseparator, starting the search from the end. So ExtractFileExt('/home/user/booth/.config/bill/privatefile') wiil return an empty string on all platforms. Which IMO is by design as .config/bill/privatefile in no way can be assumed to be a file extenstion. Bart ---------------------------------------------------------------------- marcov · 2021-08-26 19:48 Quote from: PascalDragon on August 26, 2021, 03:22:32 pmQuote from: winni on August 20, 2021, 04:07:47 pmWhat is wrong with this? What do you think should be the result? The question is whether ExtractFileExt is supposed to take a path or merely a filename. If the later then there is indeed nothing wrong with it, but if it's supposed to take a path then the result for the path /home/user/booth/.config/bill/privatefile as posted by QEnnay is wrong as ExtractFileExt will return .config/bill/privatefile instead of an empty string. As far as I know, extractfileext should not need info from the filesystem. So it can't know if the last bit is a file or a dir. But it does not seems logical to cross directory separators ("/") bounderies to synthesize the extension ---------------------------------------------------------------------- PascalDragon · 2021-08-28 10:17 Quote from: marcov on August 26, 2021, 09:48:57 pmQuote from: PascalDragon on August 26, 2021, 03:22:32 pmQuote from: winni on August 20, 2021, 04:07:47 pmWhat is wrong with this? What do you think should be the result? The question is whether ExtractFileExt is supposed to take a path or merely a filename. If the later then there is indeed nothing wrong with it, but if it's supposed to take a path then the result for the path /home/user/booth/.config/bill/privatefile as posted by QEnnay is wrong as ExtractFileExt will return .config/bill/privatefile instead of an empty string. As far as I know, extractfileext should not need info from the filesystem. So it can't know if the last bit is a file or a dir. That's not what I meant. Quote from: marcov on August 26, 2021, 09:48:57 pmBut it does not seems logical to cross directory separators ("/") bounderies to synthesize the extension That's what I meant and what ExtractFileExt already seems to do correctly, so the question is what QEnnay expected the function to return when they passed in /home/user/booth/.config/bill/privatefile, cause the expected result and what is currently indeed returned is an empty string. ---------------------------------------------------------------------- munair · 2021-09-03 21:37 Quote from: QEnnay on August 20, 2021, 12:12:19 amWith a Linux ".folder" in the middle of a path it returns what looks to be a single "dot", the text in debugger is too small to see exactly. No it doesn't. In your particular case ExtractFileExt() returns an empty string, not a single dot. The function is even clever enough to figure out that "/home/user/booth/.config" is not an extension either (it still returns an empty string, as it should).