Sub KopieerNieuweMP3sNaarGSM_ADB()
Dim sADB As String
Dim sMapMP3s As String
Dim sGSMMap As String
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim dGrens As Date
Dim nGekopieerd As Long
Dim sCmd As String
Dim sLogBestand As String
' === INSTELLINGEN ===
sADB = "C:\adb\adb.exe" ' Pad naar adb.exe
sMapMP3s = "C:\MijnMuziek\" ' Map met MP3's op PC
sGSMMap = "/sdcard/Music/" ' Doelmap op GSM (Android-pad)
sLogBestand = "C:\adb\kopie_log.txt" ' Logbestand
dGrens = Now() - 3 ' Grens: 3 dagen geleden
' ====================
Set oFSO = CreateObject("Scripting.FileSystemObject")
' Controleer of ADB bestaat
If Not oFSO.FileExists(sADB) Then
MsgBox "ADB niet gevonden op: " & sADB, vbCritical
GoTo Opruimen
End If
' Controleer of de GSM verbonden is
Dim sTestCmd As String
sTestCmd = sADB & " devices"
Shell "cmd /c " & sTestCmd & " > C:\adb\devices.txt 2>&1", vbHide
Application.Wait Now() + TimeValue("00:00:02")
Dim sDevices As String
Dim iFile As Integer
iFile = FreeFile
Open "C:\adb\devices.txt" For Input As #iFile
Dim sRegel As String
Do While Not EOF(iFile)
Line Input #iFile, sRegel
sDevices = sDevices & sRegel
Loop
Close #iFile
If InStr(sDevices, "device") = 0 Or InStr(sDevices, "List of devices") = InStr(sDevices, "device") Then
MsgBox "Geen GSM gevonden via ADB!" & vbCrLf & _
"Controleer USB-debugging en de USB-verbinding.", vbCritical
GoTo Opruimen
End If
' Loop door MP3's en kopieer recente bestanden
Set oFolder = oFSO.GetFolder(sMapMP3s)
nGekopieerd = 0
' Open logbestand
Dim iLog As Integer
iLog = FreeFile
Open sLogBestand For Output As #iLog
Print #iLog, "Kopie log - " & Now()
Print #iLog, String(40, "-")
For Each oFile In oFolder.Files
If LCase(oFSO.GetExtensionName(oFile.Path)) = "mp3" Then
If oFile.DateLastModified >= dGrens Then
' Bouw ADB push commando
' Spaties in bestandsnaam opvangen met aanhalingstekens
sCmd = Chr(34) & sADB & Chr(34) & " push " & _
Chr(34) & oFile.Path & Chr(34) & " " & _
Chr(34) & sGSMMap & oFile.Name & Chr(34)
' Uitvoeren via CMD
Shell "cmd /c " & sCmd & " >> " & Chr(34) & sLogBestand & Chr(34) & " 2>&1", vbHide
Print #iLog, "Gekopieerd: " & oFile.Name & " (" & _
Format(oFile.DateLastModified, "dd-mm-yyyy hh:mm") & ")"
nGekopieerd = nGekopieerd + 1
' Korte pauze tussen bestanden
Application.Wait Now() + TimeValue("00:00:01")
End If
End If
Next oFile
Print #iLog, String(40, "-")
Print #iLog, "Totaal gekopieerd: " & nGekopieerd
Close #iLog
MsgBox nGekopieerd & " MP3('s) gekopieerd naar de S23 Ultra." & vbCrLf & _
"Log: " & sLogBestand, vbInformation
Opruimen:
Set oFile = Nothing
Set oFolder = Nothing
Set oFSO = Nothing
End Sub