For an iPhone Firemonkey application I am storing files (images) in the ‘tmp’ folder and using them in my application. I want to be able flush the cache by deleting say all of the ‘.jpg’ files on demand, but I cannot seem to programatically match them in a FindFirst() call.
I am using a simple FindFirst() / FindNext() / FindClose() loop to list (and delete) the contents of a folder.
Under windows the code works perfectly. The same application under iOS (iPhone) is always returning a value of -1 (error) for the FindFirst() call, and SearchRec.Name is blank. I have tried using various file patterns including ‘.‘ with no success.
I know the files exist because I can read and write to them (under both iOS and windows) without error, and their contents is correct. A FileExists() check also returns True.
Also, if I specify a file pattern with no wildcard, to check for a known file (which really isn’t the point of a FindFirst() call), the call never returns (again this is fine under windows)!
Has anyone had any success with this under iOS and can offer any thoughts?
Thanks,
EDIT: Code snippet as requested which demonstrates the problem.
Note: _sFolderName contains the cache folder name which I have confirmed is definitely correct.
function GetCacheFileList : string;
var
iResult: integer;
sr: TSearchRec;
sPath,
sTemp: string;
sFilename : TFilename;
begin
sTemp := '';
sFilename := _sFolderName + '*.jpg';
//
iResult := FindFirst(sFilename, faAnyFile, sr); // ALWAYS RETURNS -1 under iOS
while (iResult = 0) do
begin
sTemp := sTemp + sr.Name + sLineBreak;
iResult := FindNext(sr)
end; { while }
//
FindClose(sr);
Result := sTemp
end;
This has been fixed under XE2 update 3