VBS代码:在指定文件夹中查找包含特定文本的文件夹并复制jpg图片
以下使用VBS代码实现的功能:在指定的文件夹中查找包含特定文本的文件夹,并将其中的jpg图片文件复制到桌面上的一个新文件夹。
Option Explicit
Dim objFSO, objShell, objFolder, objFile, objDestFolder
Dim desktopPath, searchFolder, searchText
' 获取桌面路径
Set objShell = CreateObject("WScript.Shell")
desktopPath = objShell.SpecialFolders("Desktop")
' 设置搜索文件夹路径和搜索文本
searchFolder = "E:\图片"
searchText = "aaa.txt"
' 创建目标文件夹
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDestFolder = objFSO.CreateFolder(desktopPath & "\找到的文件夹")
' 遍历搜索文件夹
Set objFolder = objFSO.GetFolder(searchFolder)
For Each objFile In objFolder.Files
' 判断文件夹名称是否包含搜索文本
If InStr(objFile.Name, searchText) > 0 Then
' 判断文件夹是否非空
If objFile.Size > 0 Then
' 复制jpg图片文件到目标文件夹
If LCase(objFSO.GetExtensionName(objFile.Path)) = "jpg" Then
objFSO.CopyFile objFile.Path, objDestFolder.Path & "\", True
End If
End If
End If
Next
' 清理对象
Set objFolder = Nothing
Set objDestFolder = Nothing
Set objFSO = Nothing
Set objShell = Nothing
请将以上代码复制到一个文本编辑器中,并将文件保存为后缀名为.vbs的文件,然后双击运行即可实现您所需的功能。注意,代码中的搜索文件夹路径和搜索文本需要根据实际情况进行修改。
原文地址: https://www.cveoy.top/t/topic/qbZT 著作权归作者所有。请勿转载和采集!