I have two conditions that need to traverse the same data but inside the traversal the logic changes slightly for each respective condition and in different places. If it was the same place that would be easy to factor out, but what's the best approach if it's not all in the same place for every condition? I seem to run into this situation often when parsing data.

```
switch(batch.DocumentType.ImportedFileDisposition)
{
    case ImportedFileDispositionActions.Delete:                                 
        foreach (string documentMetadataFile in documentMetadataPaths)
        {
            string documentPath = Path.GetDirectoryName(documentMetadataFile);
            XDocument metadata = XDocument.Load(documentMetadataFile);
            foreach (var pageElement in metadata.Root.Element("Pages").Elements("Page"))
            {
                string pageName = null;
                XAttribute attribute = pageElement.Attribute("FileName");
                if (attribute != null)
                    pageName = attribute.Value;

                string pagePath = null;
                string originalPagePath = null;
                if (!string.IsNullOrWhiteSpace(pageName))
                {
                    pagePath = IOUtility.PathCombine(documentPath, pageName);
                    File.Delete(pagePath);
                }
            }
            File.Delete(documentMetadataFile);
            Directory.Delete(documentPath, true);
        }
        break;
    case ImportedFileDispositionActions.Archive:
        foreach (string documentMetadataFile in documentMetadataPaths)
        {
            string documentPath = Path.GetDirectoryName(documentMetadataFile);
            string baseImportDirectory = documentPath;
            string archiveDirectory = GenerateArchiveDirectory(batch, documentPath);
            XDocument metadata = XDocument.Load(documentMetadataFile);
            foreach (var pageElement in metadata.Root.Element("Pages").Elements("Page"))
            {
                string pageName = null;
                XAttribute attribute = pageElement.Attribute("FileName");
                if (attribute != null)
                    pageName = attribute.Value;

                string pagePath = null;
                string originalPagePath = null;
                if (!string.IsNullOrWhiteSpace(pageName))
                {
                    pagePath = IOUtility.PathCombine(documentPath, pageName);
                    string newArchivePath = IOUtility.PathCombine(archiveDirectory, pageName);
                    try
                    {
                        IOUtility.MoveFile(pagePath, newArchivePath);
                    }
                    catch
                    {
                        try
                        {
                            IOUtility.CopyFile(pagePath,newArchivePath, true);
                        }
                        catch (Exception ex)
                        {
                            throw new IOException("Failed to move or copy file: " + pagePath + " to archive: " + newArchivePath, ex);
                        }
                    }
                    File.Delete(pagePath);
                }
            }
            File.Delete(documentMetadataFile);
            Directory.Delete(documentPath, true);
        }
        break;
}

```