Skip to content

Instantly share code, notes, and snippets.

@stack
Created November 11, 2010 17:56
Show Gist options
  • Save stack/672905 to your computer and use it in GitHub Desktop.
Save stack/672905 to your computer and use it in GitHub Desktop.
A script for copying files from a corrupt hard drive
$source = $args[0];
$dest = $args[1];
$files = Get-ChildItem "$source" -recurse
foreach($file in $files) {
if ($file.psiscontainer) {
$common_directory = $file.FullName.Replace($source, "")
$new_directory = $dest + $common_directory
Write-Host "Creating directory $new_directory"
New-Item $new_directory -type directory
} else {
$source_file = $file.FullName
$common_path = $source_file.Replace($source, "")
$new_file = $dest + $common_path
Write-Host "Copying $source_file to $new_file"
Copy-Item $source_file $new_file -ErrorAction Stop
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment