# File lib/file_systems/CbmDos.rb, line 252
  def self.delete_file(file_system_image,filename)
  directory_filename=directory_entry_for_filename(filename)
  #first find this file's directory entry

  directory_track_no=18
  directory_sector_no=1  
  while (directory_track_no !=0) do
    directory=file_system_image.get_sector(directory_track_no,directory_sector_no)    
    raise "attempted to read invalid directory sector at T #{directory_track_no} S#{directory_sector_no}" if directory.nil?
    8.times do |slot_no|
      slot_start=slot_no*0x20
      next if directory[slot_start+2]==0 #skip files that are already deleted

      if directory[slot_start+5,16]==directory_filename then
        #found our file!

#        puts "found #{filename} at T #{directory_track_no} S #{directory_sector_no} slot #{slot_no}"


        #clear the directory entry

        directory[slot_start+2]=0
        file_system_image.set_sector(directory_track_no,directory_sector_no,directory)
        #now mark the file sectors as being free in the BAM

        file_track_no=directory[slot_start+3]
        file_sector_no=directory[slot_start+4]
        
        until (file_track_no==0) do
#          puts "freeing T #{file_track_no} S #{file_sector_no}"

          mark_sector_as_free(file_system_image,file_track_no,file_sector_no)
          file_sector=file_system_image.get_sector(file_track_no,file_sector_no)
          file_track_no=file_sector[0]
          file_sector_no=file_sector[1]
        end
        return
      end
    end
    directory_track_no=directory[00]
    directory_sector_no=directory[01]    
  end
end