Vbscript 列出文件夹和子文件夹中的所有 PDF 文件 [英] Vbscript list all PDF files in folder and subfolders

查看:32
本文介绍了Vbscript 列出文件夹和子文件夹中的所有 PDF 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这是我的代码,但我无法使用 objFile.Extension 过滤列表,我确定这是愚蠢的事情

Well here is my code but I just can not filter the listing using the objFile.Extension i am sure it is some thing silly

Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:dev"

Set objFolder = objFSO.GetFolder(objStartFolder)
Wscript.Echo objFolder.Path

Set colFiles = objFolder.Files

For Each objFile in colFiles
If objFile.Extension = "PDF" Then
    Wscript.Echo objFile.Name
    End If
Next
Wscript.Echo

ShowSubfolders objFSO.GetFolder(objStartFolder)

Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
        Wscript.Echo Subfolder.Path
        Set objFolder = objFSO.GetFolder(Subfolder.Path)
        Set colFiles = objFolder.Files
        For Each objFile in colFiles
            Wscript.Echo objFile.Name
        Next
        Wscript.Echo
        ShowSubFolders Subfolder
    Next
End Sub

运行时返回错误

(11, 1) Microsoft VBScript 运行时错误:对象不支持此属性或方法:'objFile.Extension'

(11, 1) Microsoft VBScript runtime error: Object doesn't support this property or method: 'objFile.Extension'

推荐答案

您需要使用 GetExtensionName 方法在 FileSystemObject 对象上.

You'll want to use the GetExtensionName method on the FileSystemObject object.

Set x = CreateObject("scripting.filesystemobject")
WScript.Echo x.GetExtensionName("foo.pdf")

在你的例子中,尝试使用这个

In your example, try using this

For Each objFile in colFiles
    If UCase(objFSO.GetExtensionName(objFile.name)) = "PDF" Then
        Wscript.Echo objFile.Name
    End If
Next

这篇关于Vbscript 列出文件夹和子文件夹中的所有 PDF 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆