标题: [问题求助] 如何用VBS查找文件名以指定字符串开头的文件/筛选文件名? [打印本页]
作者: 3Q3Q 时间: 2009-12-10 11:03 标题: 如何用VBS查找文件名以指定字符串开头的文件/筛选文件名?
本帖最后由 pcl_test 于 2017-3-20 17:44 编辑
某个文件夹内有大量文件,只筛选出特定文件名的文件,例如 LPD_*.TXT,不必筛选子文件夹,谢谢!
作者: rwxyxy 时间: 2009-12-10 18:31
用正则吧!
作者: zqz0012005 时间: 2009-12-10 21:48
- folder = "D:\桌面\"
- set fso = CreateObject("Scripting.FileSystemObject")
- set file = fso.GetFolder(folder).Files
- for each f in files
- fn = f.name
- if InStr(1, fso.GetBaseName(fn), "LPD_", 1)=1 and LCase(Right(fn,3))=LCase("txt") then
- s = s & fn & vbCrLf
- end if
- next
- wsh.echo s
复制代码
作者: zqz0012005 时间: 2009-12-10 21:54
只适用于 Windows XP 及以上版本- folder = "D:\桌面\"
-
- if Right(folder,1) <> "\" then folder = folder & "\"
- folder = Replace(folder, "\", "\\")
- set wmi = GetObject("winmgmts:")
- set files = wmi.ExecQuery("select * from CIM_DataFile where (" _
- & "drive='" & Left(folder, 2) & "' and path='" _
- & Mid(folder,3) & "' and extension='txt' and " _
- & "filename like '" & "LPD_%" & "')")
- for each f in files
- s = s & f.name & vbCrLf
- next
- wsh.echo s
复制代码
(可能存在未知原因导致文件获取不完整)
作者: 3Q3Q 时间: 2009-12-14 09:08
谢谢您的回答!请问有包含通配符格式的筛选方法么?比如,IF 文件名=LPD_*.txt THEN ....
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |