-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_transfer.ps1
56 lines (47 loc) · 2.18 KB
/
auto_transfer.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Function to eject the card
function Eject-SDCard {
param([string]$driveLetter)
$eject = New-Object -comObject Shell.Application
$eject.NameSpace(17).ParseName($driveLetter + ":").InvokeVerb('Eject')
}
$waitingForCard = $true
# Main loop
while ($true) {
# Check if the drive is available
if (Test-Path 'K:\') {
Write-Host "Detected card."
$waitingForCard = $true # Reset flag after detection for next cycle
# Stage 1: Generate a folder with the current date and time
$destinationPath = "I:\SD_Card_Backup\" + (Get-Date -Format "dd-MM-yyyy-HH-mm-ss")
New-Item -ItemType Directory -Path $destinationPath
# Stage 2: Use robocopy to copy all .mov and .mp4 files
$sourcePath = "K:\PRIVATE\M4ROOT\CLIP"
robocopy $sourcePath $destinationPath *.mov *.mp4 /E
# Stage 3: Use PowerShell hashing to verify all the copied files
Get-ChildItem -Path $destinationPath -Recurse | Where-Object { $_.Extension -match "mov|mp4" } | ForEach-Object {
$sourceFile = $_.FullName.Replace($destinationPath, $sourcePath)
$sourceHash = (Get-FileHash $sourceFile).Hash
$destinationHash = (Get-FileHash $_.FullName).Hash
if ($sourceHash -eq $destinationHash) {
Write-Host "Verification successful for file: $($_.Name)"
} else {
Write-Host "Verification failed for file: $($_.Name)"
}
}
# Stage 4: Eject the card
Eject-SDCard -driveLetter "K"
# Notification sound when the process is completed
[System.Media.SystemSounds]::Beep.Play()
Write-Host "Operation completed. Waiting for next card."
# Wait a bit after ejecting before next check to prevent immediate re-detection
Start-Sleep -Seconds 10
} else {
# Only print waiting for card if not already waiting
if ($waitingForCard) {
Write-Host "Waiting for card..."
$waitingForCard = $false # Prevent message from repeating
}
# Wait for 10 seconds before checking again
Start-Sleep -Seconds 10
}
}