Using a temporary variable, as removing items from a list while iterating over it causes problems. Hence created a temporary list for the filtered files.