I removed the file I uploaded previously as there were some bugs. My code is very crude as I'm only doing it for a school project and would probably not be improving it anyway.
If you have problems managing the FAT, then you would probably have misunderstood the entire FAT conecpt already! The FAT entries each represent a data cluster, starting from cluster 2. Cluster 0/1 are reserved. The value of each cluster represents the index of the next cluster where data is stored. So the FAT structure is essentially a linked list of clusters where data from a single file is stored. 0x0000 is reserved for empty clusters, while 0xFFF8-0xFFFF are reserved for end-of-file indicators. Finding the next empty cluster is simply traversing the FAT table from the beginning in search for the first entry with zero value, regardless of whether it's at the beginning, middle or at the end! Deleting a file is simply zeroing the entire linked list of FAT entries.
My method always fills data from the beginning, and probably wears out the FLASH faster, but what the heck! Of course, you may implement your own fanciful and probably faster algorithms!
Anyway, any FAT experts can tell me what makes a File/Directory entry valid to a Windows/WinCE OS? I've seen several File Entries entries that are not displayed by windows, although they seem valid. Besides the fact that they have strange filenames, they seem to have valid file parameters, and are neither flagged as hidden nor system files.