complete working code.

added transactional manager incase there is an error deleting files.
delete code finished