vbs代码制作 按照桌面aaatxt 列表内的名字匹配相关的文件夹和文件名 在E图片中查找把找到的jpg图片文件复制到桌面找到的文件夹
以下是一个使用VBScript编写的代码示例,可以按照指定的文件名列表在指定目录中查找匹配的文件,并将找到的文件复制到指定目录中:
' 定义文件名列表
Dim fileNameList
fileNameList = Array("aaa", "bbb", "ccc")
' 定义源目录和目标目录
Dim sourceDir, destDir
sourceDir = "E:\图片"
destDir = "桌面\找到的文件夹"
' 创建文件系统对象
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
' 获取桌面路径
Dim shell, desktopPath
Set shell = CreateObject("WScript.Shell")
desktopPath = shell.SpecialFolders("Desktop")
' 创建目标文件夹
Dim destFolderPath
destFolderPath = fso.BuildPath(desktopPath, destDir)
fso.CreateFolder destFolderPath
' 遍历文件名列表
Dim i
For i = 0 To UBound(fileNameList)
' 构建文件路径
Dim filePath
filePath = fso.BuildPath(sourceDir, fileNameList(i) & ".jpg")
' 检查文件是否存在
If fso.FileExists(filePath) Then
' 构建目标文件路径
Dim destFilePath
destFilePath = fso.BuildPath(destFolderPath, fileNameList(i) & ".jpg")
' 复制文件
fso.CopyFile filePath, destFilePath, True
End If
Next
' 释放对象
Set fso = Nothing
Set shell = Nothing
请注意,上述代码中的sourceDir和destDir需要根据实际情况进行修改,以确保指定的源目录和目标目录路径是正确的。另外,要确保脚本具有足够的权限来访问和操作指定的目录和文件
原文地址: https://www.cveoy.top/t/topic/iufV 著作权归作者所有。请勿转载和采集!