Windows 批量文件自动将文件从USB/DVD复制到HDD-等待插入USB/DVD(检测)
这是我的第一个Windows 批量文件自动将文件从USB/DVD复制到HDD-等待插入USB/DVD(检测),windows,batch-file,cmd,Windows,Batch File,Cmd,这是我的第一个.bat文件。我想制作一个脚本,当检测到卷到硬盘时,从USB或DVD/CD复制我的所有文件 我没有找到好东西。我认为我需要实现如下内容: while(!volume:e /*if is DVD*/ || !volume:g /*if is USB*/) keep seeking if(volume:e is detected) xcopy e:\* d:\Backup\ /s /q if(volume:g is detected) xcopy g:\* d:\Backup
.bat
文件。我想制作一个脚本,当检测到卷到硬盘时,从USB或DVD/CD复制我的所有文件
我没有找到好东西。我认为我需要实现如下内容:
while(!volume:e /*if is DVD*/ || !volume:g /*if is USB*/)
keep seeking
if(volume:e is detected)
xcopy e:\* d:\Backup\ /s /q
if(volume:g is detected)
xcopy g:\* d:\Backup /s /q
我的最终结果是:
:while
if ("wmic logicaldisk where drivetype= '2' get volumename") NEQ "No Instance(s) Available."::HERE IS THE PROBLEM
(GOTO :Syntax) else (GOTO :while)
:Syntax
xcopy e:\* d:\Backup\ /s /q
//Use DriveType=5 for DVDs
我不知道如何在NEQ
之后写入,因为如果没有连接USB,则cmd打印没有可用的实例。
,但无法正常工作
请帮帮我。。。我错过了什么?这将等待VolumeChangeEvent,然后将c:\test复制到新卷上
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set evtDevice = objWMIService.ExecNotificationQuery ("SELECT * FROM Win32_VolumeChangeEvent")
Wscript.Echo "Waiting for events ..."
Do
Set objReceivedEvent = evtDevice.NextEvent
'report an event
Wscript.Echo " Win32_Device Changed event occurred" & VBNewLine
If objReceivedEvent.EventType = 1 Then
Wscript.Echo "Type = Config Changed"
ElseIf objReceivedEvent.EventType = 2 Then
Wscript.Echo "Type = Device Arrived"
Set colItems = objWMIService.ExecQuery("Select * From Win32_Volume")
For Each objItem in colItems
If objitem.DriveType = 2 then
Wscript.Echo objItem.DriveType & " " & objItem.Name & " " & objItem.driveletter
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set SrcFldr=objShell.NameSpace(objitem.driveletter)
Set DestFldr=objShell.NameSpace("c:\test\")
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Wscript.Echo "Finished Copying"
End If
Next
ElseIf objReceivedEvent.EventType = 3 Then
Wscript.Echo "Type = Device Left"
ElseIf objReceivedEvent.EventType = 4 Then
Wscript.Echo "Type = Computer Docked"
End If
Loop
既然你已经知道要实现什么,你就应该尝试一下;当你在某一点上陷入困境时,回到这里,清楚地描述你所面临的失败。提示:要获取驱动器类型,可以使用wmic LogicalDisk get Description、DeviceID、DriveType等来获取驱动器类型。您应该试试这个vbscript,这一定是我以前从未见过的新版本的批处理。它包含在Windows 10中吗?@ThomasWeller我认为是VBScript错误:我不知道VBScript或批处理,但批处理看起来更简单。帮助…因为您没有将文件复制到的
c:\test
文件夹。创造它。批处理无法等待事件。@这是正确的。我将CD-ROM的objitem.DriveType=2
更改为objitem.DriveType=5
,但不起作用。为什么?因为你可能只是在换光盘。请尝试另一个脚本来监视驱动器号,请参阅