Final working code to extract files