Created
July 11, 2018 19:06
-
-
Save mmcev106/f6e579f8adce5a1cb5ed4c81f0e8cb9d to your computer and use it in GitHub Desktop.
Cleans up the zone files and subdirectories from migrecover output so it matches the original file/folder structure backed up by Windows Easy Transfer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dir = '/home/mceverm/Downloads/mceverm/'; | |
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); | |
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); | |
foreach($files as $file) { | |
if($file->getBasename() == '$Zone.Identifier$$DATA'){ | |
$zoneFilePath = $file->getRealPath(); | |
$dir = dirname($zoneFilePath); | |
$filename = basename($dir); | |
echo "handling: " . $zoneFilePath . "\n"; | |
$tmpFilePath = "/tmp/recovered-zoned-file"; | |
if(!rename("$dir/$filename", $tmpFilePath)){ | |
die('rename failed!'); | |
} | |
if(!unlink($zoneFilePath)){ | |
die('unlink failed!'); | |
} | |
if(!rmdir("$dir")){ | |
die('rmdir failed!'); | |
} | |
if(!rename($tmpFilePath, $dir)){ | |
die('rename2 failed!'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment