Looking to have a vbscript that can copy a folder and its contents to a active usb drive. So the script need to found the active usb drive put in it. Next copy the folder and its contests to the usb drive. Then after the copy job it done need to tell it's finish. There is what I get so far for it.
Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "C:\Test" , "?:\Test" , OverWriteFiles 'the "?:\Test" is the part set the usb drive at.
Wscript.Echo "I am Done."
So, what part I really need help with is found out what the active usb drive letter. Next tell is to copy to that usb drive letter. I know it's not alot of code. But, any info wold be a great help.
This example shows the type of each drive:
Set oFSO = CreateObject("Scripting.FileSystemObject")
sRes = ""
For Each oDrive In oFSO.Drives
sRes = sRes & "DriveLetter: " & oDrive.DriveLetter & ", DriveType: "
Select Case oDrive.DriveType
Case 0
sRes = sRes & "Unknown"
Case 1
sRes = sRes & "Removable"
Case 2
sRes = sRes & "HDD"
Case 3
sRes = sRes & "Network Drive"
Case 4
sRes = sRes & "CD-ROM"
Case 5
sRes = sRes & "RAM-Drive"
End Select
sRes = sRes & vbNewLine
Next
MsgBox sRes
Your script should be like this one:
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objDrive In objFSO.Drives
If objDrive.DriveType = 1 Then
objFSO.CopyFolder "C:\Test" , objDrive.DriveLetter & ":\Test" , True
MsgBox "Copy to " & objDrive.DriveLetter & " Completed"
End If
Next
UPD: Last drive can be found this way:
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objDrive In objFSO.Drives
Set objLastDrive = objDrive
Next
MsgBox objLastDrive.DriveLetter