Skip to content

Instantly share code, notes, and snippets.

@mmcev106
Created July 11, 2018 19:06
Show Gist options
  • Save mmcev106/f6e579f8adce5a1cb5ed4c81f0e8cb9d to your computer and use it in GitHub Desktop.
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.
<?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