[SOLVED] problem with FileExists() lazarus / 31-LCL ---------------------------------------------------------------------- petevick · 2023-04-18 15:03 I'm having a problem detecting if a file exists after changing a file name to lowercase. Example code is.... 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   if SaveDialog.Execute then begin    FileNm:= LowerCase(SaveDialog.FileName);    if FileExists(FileNm) then begin    if QuestionDlg('File Exists', 'The file '''+ExtractFileName(FileNm)+        ''' already exists.'+        sLineBreak+'Click Replace to overwrite.', mtConfirmation,        [mrNo, '&Cancel','IsDefault',mrYes,'&Replace'],0) = mrYes then SaveFile;    end else SaveFile;  end;Now I know for sure that the file name I typed into SaveDialog exists, but it does not trigger the QuestionDlg. If I remove the LowerCase()..... 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   if SaveDialog.Execute then begin    FileNm:= SaveDialog.FileName;    if FileExists(FileNm) then begin      if QuestionDlg('File Exists', 'The file '''+ExtractFileName(FileNm)+        ''' already exists.'+        sLineBreak+'Click Replace to overwrite.', mtConfirmation,        [mrNo, '&Cancel','IsDefault',mrYes,'&Replace'],0) = mrYes then SaveFile;    end else SaveFile;  end;....then QuestionDlg is triggered. So it's obvious (to me) that LowerCase() is the culprit, but it's taking a String variable so should be returning a String variable surely. Everything I've tried to ensure the file name is lowercase results in the QuestionDlg not being triggered. What am I missing ??? ---------------------------------------------------------------------- Josh · 2023-04-18 15:13 if file name is 'This_Is_A_File.TxT', you convert it to 'this_is_a_file.txt' withe Lowercase. then check if the lowercae file exists, which in a case sensitive OS it is not the same file as  'This_Is_A_File.TxT' ---------------------------------------------------------------------- KodeZwerg · 2023-04-18 15:15 Tested with SysUtils.FileExists() method on Windows and can not confirm what you wrote. 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   if SaveDialog1.Execute then  begin    Label1.Caption := SaveDialog1.FileName;    Label2.Caption := LowerCase(SaveDialog1.FileName);    s := LowerCase(SaveDialog1.FileName);    if FileExists(s) then      Self.Caption := 'True'      else      Self.Caption := 'False';  end;Lazarus 2.3.0 (rev main-2_3-3223-g00a23612bf) FPC 3.2.2 x86_64-win64-win32/win64 ---------------------------------------------------------------------- petevick · 2023-04-18 15:18 Quote from: Josh on April 18, 2023, 05:13:38 pmif file name is 'This_Is_A_File.TxT', you convert it to 'this_is_a_file.txt' withe Lowercase. then check if the lowercae file exists, which in a case sensitive OS it is not the same file as  'This_Is_A_File.TxT' Correct, but I type in 'TEST.TXT', after conversion it's 'test.txt' which I know exists. As I explained above, the file is found if I remove the LowerCase() and type in 'test.txt' ---------------------------------------------------------------------- petevick · 2023-04-18 15:19 Quote from: KodeZwerg on April 18, 2023, 05:15:26 pmTested with SysUtils.FileExists() method on Windows and can not confirm what you wrote. 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   if SaveDialog1.Execute then  begin    Label1.Caption := SaveDialog1.FileName;    Label2.Caption := LowerCase(SaveDialog1.FileName);    s := LowerCase(SaveDialog1.FileName);    if FileExists(s) then      Self.Caption := 'True'      else      Self.Caption := 'False';  end;Lazarus 2.3.0 (rev main-2_3-3223-g00a23612bf) FPC 3.2.2 x86_64-win64-win32/win64 Tanks, but I'm using Linux. ---------------------------------------------------------------------- petevick · 2023-04-18 15:46 Quote from: KodeZwerg on April 18, 2023, 05:15:26 pmTested with SysUtils.FileExists() method on Windows and can not confirm what you wrote. 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   if SaveDialog1.Execute then  begin    Label1.Caption := SaveDialog1.FileName;    Label2.Caption := LowerCase(SaveDialog1.FileName);    s := LowerCase(SaveDialog1.FileName);    if FileExists(s) then      Self.Caption := 'True'      else      Self.Caption := 'False';  end;Lazarus 2.3.0 (rev main-2_3-3223-g00a23612bf) FPC 3.2.2 x86_64-win64-win32/win64 I've just tried it myself in a Windows VM, and yes it does work as expected. It's usually Linux that plays nicely ---------------------------------------------------------------------- cdbc · 2023-04-18 15:58 Hi Could this be codepage related...? 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   FileNm:= LowerCase(Utf8ToSys(SaveDialog.FileName)); Does the above help... Regards Benny ---------------------------------------------------------------------- alpine · 2023-04-18 16:37 I believe SaveDialog1.FileName holds also the full path of the file. Are you lowercasing a capital letter into the file path? ---------------------------------------------------------------------- petevick · 2023-04-18 16:56 Quote from: alpine on April 18, 2023, 06:37:45 pmI believe SaveDialog1.FileName holds also the full path of the file. Are you lowercasing a capital letter into the file path? you know what, I've stared and stared at variables with and without LowerCase() until my eyes were sore, and convinced myself they were identical, and of course there was one capital in the path. Feeling a tad   Thanks for making me look at it again alpine, Thanks all for posting, much appreciated.