怎么用vbs实现

2025-04-08 16:55:42
推荐回答(2个)
回答1:

以下代码本机测试通过,基本上都有注释,有问题就追问:

dim folder,fso,foldername,strInput,spath,sword
set fso=createobject("scripting.filesystemobject")
strInput=inputbox("请输入要搜索的文件夹路径,需要搜索的文件名,复制到的路径","提示(以下三个内容以逗号隔开)","C:,1.txt,D:\") '注意:搜索路径后面不能要斜杠,复制路径后面必须要斜杠
strInput=split(strInput,",") '获取输入字符串
spath=strInput(0) '获取路径
sword=lcase(strInput(1)) '获取关键词
call scan_str(spath,sword,strInput(2))

sub scan_str(folder_,sword,yPath)
on error resume next
set folder_=fso.getfolder(folder_)
set files=folder_.files
for each file in files
fname=fso.GetFileName(file) '获取文件后缀
fname=lcase(fname) '后缀名转换成小写字母
if fname = sword then
fso.CopyFile folder_ & "\" & fname,yPath
end if
next
set subfolder=folder_.subfolders '搜索子目录
for each subfolders in subfolder
call scan_str(subfolders,sword,yPath)
next
end sub

回答2:

vbs无法实现点击,只能实现按键。可以试试按键精灵