DeleteFile doesn't work lazarus / 68-Other OS ---------------------------------------------------------------------- HermanR · 2015-06-01 17:57 Hello, (Lazarus 1.4.0 / pfc 2.6.4 / Windows Embedded Handheld 6.5 Professional (CE OS 5.2.29153) I have the following code:   if SysUtils.FindFirst(fLogDir + '*.*', faAnyFile and not faDirectory, sr) = 0 then     repeat       FileAge(fLogDir + sr.Name, dt);       if DaysBetween(Now, dt) > AAge then       begin         DeleteFile(PWideChar(fLogDir + sr.Name));         --log fLogDir + sr.Name --here       end;     until SysUtils.FindNext(sr) <> 0;   SysUtils.FindClose(sr); In the log line al file older the 10 days are shown, but none is deleted. When i use FileExists, the file exists. I can delete the files manualy I read and tested UTFToAnsi conversion, that didn't help. can anyone help me on this? Thanks in advance Herman ---------------------------------------------------------------------- rvk · 2015-06-01 18:31 What version (from what unit) of DeleteFile are you using? (not http://www.freepascal.org/docs-html/rtl/sysutils/deletefile.html because that one just needs a string) Are you sure you need to supply a PWideChar to that function? And shouldn't you first convert "fLogDir + sr.Name" to widechar before casting it to a PWideChar? Does this not work? Code: [Select]DeleteFile(fLogDir + sr.Name); (Ps. Please use the code-tags around code in your posts. It read much easier) ---------------------------------------------------------------------- marcov · 2015-06-01 18:53 For the Windows version try Windows.Deletefile() ---------------------------------------------------------------------- rvk · 2015-06-01 19:16 And please note that the Windows.DeleteFile() is linked with the DeleteFileA Windows-api. So it needs a PChar (AnsiChar) and not a PWideChar. If you have unicode-characters in your filename you'll need to use FileUtil.DeleteFileUtf8(); ---------------------------------------------------------------------- rx3.fireproof · 2015-06-01 19:32 Hello Yesterday I fought with a similar problem after upgrading to Lazarus 1.4.0. I have the names of files and folders can be Cyrillic.  I solved the problem after using the functions with utf8. Example var myxml :TXMLConfig; begin myxml:=Txmlconfig.Create(systoutf8(ExtractFilePath(Application.exeName ))+'myfile.xml'); end; or begin if  savedialog1.Execute then begin   if FileExistsUTF8(SaveDialog1.FileName) then DeleteFileUTF8(savedialog1.FileName); end; In version 1.2.6 I have worked functions without utf8. ---------------------------------------------------------------------- marcov · 2015-06-01 20:08 Quote from: rvk on June 01, 2015, 09:16:00 pmAnd please note that the Windows.DeleteFile() is linked with the DeleteFileA Windows-api. There is no DeleteFileA  API on wince, and WinCE defines FPC_UNICODE_OS, so Windows unit is compiled with -W by default. At least 3.x is. 2.x is too long ago for me:-) ---------------------------------------------------------------------- rvk · 2015-06-01 20:59 Quote from: marcov on June 01, 2015, 10:08:57 pmQuote from: rvk on June 01, 2015, 09:16:00 pmAnd please note that the Windows.DeleteFile() is linked with the DeleteFileA Windows-api. There is no DeleteFileA  API on wince, and WinCE defines FPC_UNICODE_OS, so Windows unit is compiled with -W by default. Ok... If that's the case the string would first need to be converted to Widestring. So this should do the trick: Code: [Select]DeleteFile(PWideChar(UTF8Decode(fLogDir + sr.Name))); (UTF8Decode for converting the UTF8 to Unicodestring/Widestring) (Or is the string-type in lazarus/wince also already Unicode ???) ---------------------------------------------------------------------- HermanR · 2015-06-02 10:02 SOLVED fLogDir = \My Documents\Log\ sr = TSearchRec I tested all you guys adviced and reduced the solution to the next line. DeleteFile(PWideChar(WideString(fLogDir + sr.Name))); The conversion to WideString before making the pointer did the trick Thanks all Herman