Last active
September 1, 2016 15:20
-
-
Save henices/9828cbe0921a6e749e6c6690e69e6885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Set objFSO = CreateObject("Scripting.FileSystemObject") | |
| outputDir = "C:\output" | |
| objStartFolder = "C:\Rainbow\" | |
| filename = "C:\文件名.txt" | |
| If objFSO.FolderExists(outputDir) Then | |
| objFSO.DeleteFolder(outputDir) | |
| End If | |
| ' 找到的文件放在 outputDir | |
| objFSO.CreateFolder(outputDir) | |
| Set objFolder = objFSO.GetFolder(objStartFolder) | |
| Set colFiles = objFolder.Files | |
| Set colFlds = objFolder.SubFolders | |
| ' D:\文件名.txt 要查找的文件或文件夹,每个一行 | |
| Set dict = CreateObject("Scripting.Dictionary") | |
| Set file = objFSO.OpenTextFile (filename, 1) | |
| row = 0 | |
| Do Until file.AtEndOfStream | |
| line = file.Readline | |
| dict.Add row, line | |
| row = row + 1 | |
| Loop | |
| file.Close | |
| For Each line in dict.Items | |
| For Each file in colFiles | |
| If Instr(file, line) Then | |
| objFSO.CopyFile objStartFolder & file.name, outputDir & "\" & file.name | |
| End If | |
| Next | |
| For Each fld in colFlds | |
| If InStr(fld, line) Then | |
| objFSO.CopyFolder objStartFolder & fld.name, outputDir & "\" & fld.name | |
| End If | |
| Next | |
| Next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment