Skip to content

Instantly share code, notes, and snippets.

@aadennis
Last active June 11, 2017 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aadennis/a2e7ab9a3f0dccbcce28987d0c98f136 to your computer and use it in GitHub Desktop.
Save aadennis/a2e7ab9a3f0dccbcce28987d0c98f136 to your computer and use it in GitHub Desktop.
# Try to copy all named files starting with the biggest to e.g. a DVD
# Once less than $minAllowedSpace, exit, in the hope that a bit of contingency on the DVD
# makes it easier to read and write files... which are a pain on a DVD writer.
#Remove-Item -Path E:\Set1 -Recurse -Force
$srcDir = "G:\VideosCollection\TheRest\MP4"
$targetDir = "E:\Set3"
$minAllowedSpace = 100mB
$set = gci -Path $srcDir -Filter *.mp4 | Sort-Object -Property Length -Descending
$counter = 1
$set | % {
$disk = Get-WmiObject Win32_LogicalDisk -ComputerName localhost -Filter "DeviceID='E:'" | Select-Object Size,FreeSpace
$diskFreeSpace = $disk.FreeSpace
if ($diskFreeSpace -lt $minAllowedSpace) {
$diskFreeSpaceAsMb = [decimal]::round($diskFreeSpace/1MB)
"diskFreeSpace is now [$diskFreeSpaceAsMb]Mb. Exiting..."
exit
}
$file = $_
$baseName = $file.BaseName
$source = "$srcDir/$baseName.mp4"
$target = "$targetDir/$baseName.mp4"
"Processing [$counter][$source]"
Copy-Item -Path $source -Destination $target -ErrorAction Continue
Start-Sleep 3
$counter++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment