vbs代码制作在E图片中查找 aaatxt文件列表模糊匹配的文件夹把找到的jpg图片文件复制到桌面找到的文件夹
以下是使用vbs代码实现在"E:\图片"中查找aaa.txt文件列表模糊匹配的文件夹,并将找到的jpg图片文件复制到桌面\找到的文件夹的示例代码:
Dim objFSO, objShell, objFolder, objFile, objDestFolder
' 设置源文件夹路径和目标文件夹路径
Dim sourceFolderPath, destFolderPath
sourceFolderPath = "E:\图片"
destFolderPath = "C:\Users\YourUsername\Desktop\找到的文件夹" ' 替换为你的用户名
' 创建文件系统对象
Set objFSO = CreateObject("Scripting.FileSystemObject")
' 创建Shell对象
Set objShell = CreateObject("WScript.Shell")
' 创建目标文件夹
objFSO.CreateFolder destFolderPath
' 打开aaa.txt文件并逐行读取文件夹名
Dim objTextFile, folderName
Set objTextFile = objFSO.OpenTextFile("E:\图片\aaa.txt", 1)
' 逐行读取文件夹名,并在源文件夹中查找匹配的文件夹
Do Until objTextFile.AtEndOfStream
folderName = objTextFile.ReadLine
' 构建文件夹路径
folderPath = objFSO.BuildPath(sourceFolderPath, folderName)
' 检查文件夹是否存在
If objFSO.FolderExists(folderPath) Then
' 打开文件夹
Set objFolder = objFSO.GetFolder(folderPath)
' 遍历文件夹中的文件
For Each objFile In objFolder.Files
' 检查文件扩展名是否为jpg
If LCase(objFSO.GetExtensionName(objFile.Path)) = "jpg" Then
' 构建目标文件路径
destFilePath = objFSO.BuildPath(destFolderPath, objFile.Name)
' 复制文件到目标文件夹
objFSO.CopyFile objFile.Path, destFilePath, True
End If
Next
End If
Loop
' 清理对象
Set objFSO = Nothing
Set objShell = Nothing
Set objFolder = Nothing
Set objFile = Nothing
Set objDestFolder = Nothing
Set objTextFile = Nothing
请先将代码中的YourUsername替换为你的Windows用户名,然后将代码保存为一个.vbs文件并运行即可。代码会在桌面上创建一个名为"找到的文件夹"的文件夹,并将匹配到的jpg图片文件复制到该文件夹中
原文地址: https://www.cveoy.top/t/topic/iuhu 著作权归作者所有。请勿转载和采集!