希望有一个可以将文件夹及其内容复制到活动的USB驱动器的vbscript。所以脚本需要找到放入它的有源USB驱动器。接下来将文件夹及其竞赛复制到USB驱动器。然后在完成复制工作后,它需要告诉它完成。到目前为止我得到了它。
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."
那么,我真正需要帮助的部分是找出有效的usb驱动器号。接下来告诉的是复制到那个USB驱动器号。 我知道这不是很多代码。但是,任何信息都将是一个很大的帮助。
答案 0 :(得分:1)
此示例显示每个驱动器的类型:
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
你的脚本应该是这样的:
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:可以通过以下方式找到最后一个驱动器:
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objDrive In objFSO.Drives
Set objLastDrive = objDrive
Next
MsgBox objLastDrive.DriveLetter
答案 1 :(得分:0)
嗯,可能有不止一个"活跃" USB驱动器。没有什么能阻止我将闪存驱动器插入计算机上的每个可用USB端口。但是,您可以在计算机上识别USB驱动器(又名"可移动驱动器")并使用CopyFolder()
功能将文件夹复制到其中。
Const TYPE_REMOVABLE = 1
With CreateObject("Scripting.FileSystemObject")
For Each Drive In .Drives
If Drive.DriveType = TYPE_REMOVABLE Then
.CopyFolder "C:\Test", Drive.DriveLetter & ":\Test", True
End If
Next
End With