本帖最后由 apang 于 2013-6-2 15:10 编辑
保存为test.vbs,需要安装有MicroSoft OFFICE软件
复制U盘上含 初级焊工 或者含 水平测试 的word文档到D:\筛选(如果是含 初级焊工 并且含 水平测试,将26行or改成and)
楼主没考虑文件重名的情况,如果有重名,则在文件名后依次加[1]、[2]等数字。试试看吧- DstDir = "D:\筛选"
- Set fso = CreateObject("Scripting.FileSystemObject")
- If Not fso.FolderExists(DstDir) Then fso.CreateFolder(DstDir)
-
- Set objWord=CreateObject("Word.Application")
- Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
- & ".\root\cimv2")
-
- For Each Drv in fso.Drives
- If Drv.DriveType = 1 Then
- Set colFiles = objWMI.ExecQuery("Select * from CIM_DataFile " _
- & "where Drive = '"&Drv.Path&"' and Extension Like 'doc%'")
- For Each File in colFiles
- CopyDocFile File.Name
- Next
- Set colFiles = Nothing
- End If
- Next
-
- Sub CopyDocFile(f)
- n = 0
- Set objDoc = objWord.Documents.Open(f)
- str = objDoc.Range.Text
- objDoc.Saved = False : objDoc.Close
- Set objDoc = Nothing
- If InStr(str,"初级焊工") or InStr(str,"水平测试") Then
- Name = fso.GetBaseName(f) : NewName = Name
- Ext = "." & fso.GetExtensionName(f)
- While fso.FileExists(DstDir & "\" & NewName & Ext)
- n = n + 1
- NewName = Name & "[" & n & "]"
- Wend
- fso.GetFile(f).Copy DstDir & "\" & NewName & Ext
- End If
- End Sub
-
- Set objWMI = Nothing : objWord.Quit : Set objWord = Nothing
- MsgBox "OK"
复制代码 修改一下 |