Number of file in a folder problem

Hello,
I work actually, in xojo, and i have a problem with the number of file in a folder,
in my code , i want to delete one folder,the file inside ,and replace it by a new folder empty
,the code has follow seems working good(folder and files are deleted,new empty folder created,)… but sometimes in my programm in use , the msgbox number of file in the folder, back a wrong count ( ie : 3 files, told me 4 files !) ,and i dont understand why.(its always +1 file)

this problems occurs when i restart my programm , i think its a problem a copy file or move file in the folder,

thks for your help
the code as follow

f= specialfolder.desktop.child(“essaititi”).child(“photos”).child(“img”).child(“mesphotos”)
if f.Exists then //if exits ok
numberpicture= f.Count//number of file
MsgBox" number of picture +"+str(numberpicture)
if numberpicture=0 then //file empty so we can delete the folder
f.Delete// folder deleted
If f.LastErrorCode > 0 then
MsgBox Str(f.LastErrorCode)
Else
MsgBox "folder empty deleted ,new folder created "
End if
//create new folder
f.CreateAsFolder
f.Name=“mesphotos”
else //delete file in the folder
for i as integer= f.Count DownTo 1
if f.item(i).Directory = False then
f.TrueItem(i).Delete
//f.item(i).Delete
end if
next
f.Delete//and we delete the folder
If f.LastErrorCode > 0 then
MsgBox Str(f.LastErrorCode)
Else
MsgBox “Folder deleted with file ,new folder created!”
f.CreateAsFolder
f.Name=“mesphotos”
end if
end
else
msgbox “file not found”
end if

Are-you aware that the current OS is adding invisible file(s) into your folder(s) and f.Count return it as the # of item(s) in that folder ?

Also, you cannot delete a folder that have items in it (f.Delete above represent a folder).

Hello,
for deleting folders an the files/subfolders in them these threads may be useful:
https://forum.xojo.com/23081-delete-a-folder
https://forum.xojo.com/22468-why-can-t-i-delete-a-folderitem-and-all-subdirectories-files-wr