Forum > Other OS
DeleteFile doesn't work
HermanR:
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:
<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);
</code>
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:
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: ---DeleteFile(fLogDir + sr.Name);
--- End code ---
(Ps. Please use the code-tags around code in your posts. It read much easier)
marcov:
For the Windows version try Windows.Deletefile()
rvk:
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:
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.
Navigation
[0] Message Index
[#] Next page