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

查看:126
本文介绍了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

在运行时,它会返回错误

On run it comes back with the error

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

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

推荐答案

您将要使用

在您的示例中,尝试使用此

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天全站免登陆