Created
November 11, 2010 17:56
-
-
Save stack/672905 to your computer and use it in GitHub Desktop.
A script for copying files from a corrupt hard drive
This file contains hidden or 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
$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