Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript 如何在VB脚本中检索不同扩展名的文件?_Vbscript - Fatal编程技术网

Vbscript 如何在VB脚本中检索不同扩展名的文件?

Vbscript 如何在VB脚本中检索不同扩展名的文件?,vbscript,Vbscript,嗨,我必须写一个代码,在那里我可以输入我想要的文件扩展名,并将这些扩展名的文件只拉到我的excel中。文件夹包含各种扩展名的文件。 到目前为止,我写的是用户可以输入*如果他想要所有的文件。但我要做的是,用户可以输入.txt/.pdf等,然后只拉那些fils.Plz帮助 Do while x=0 strAnswer = InputBox("Please enter the file extension * For all files:", _ "File Extension") If

嗨,我必须写一个代码,在那里我可以输入我想要的文件扩展名,并将这些扩展名的文件只拉到我的excel中。文件夹包含各种扩展名的文件。 到目前为止,我写的是用户可以输入*如果他想要所有的文件。但我要做的是,用户可以输入.txt/.pdf等,然后只拉那些fils.Plz帮助

Do while x=0
strAnswer = InputBox("Please enter the file extension  *  For all files:", _
    "File Extension")
If strAnswer = "" Then
        MsgBox"You must enter an extension."
Else
        a=strAnswer
        Exit Do
    End If
Loop
If a="*" Then
intRow = 2
'strFileName = "T:\public\Madhumita\New.xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
'objWorkbook.SaveAs(strFileName)
objExcel.Cells(1, 1).Value = "Folder"
objExcel.Cells(1, 2).Value = "File Name"
objStartFolder = "T:\public\Madhumita\Madhu"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
objExcel.Cells(intRow, 1).Value = objfolder.Name
objExcel.Cells(intRow, 2).Value = objFile.Name
intRow = intRow + 1
Next
objExcel.Range("A1:B1").Select
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
Sub SaveAs() 
    Application.Dialogs(xlDialogSaveAs).Show 
End Sub 
End If


objExcel.Quit
MsgBox "Done"

使用
objFSO.GetExtensionName(objFile.Path)
获取文件的扩展名。与用户提供的值进行比较,如果相等,则添加到工作表。

您可以使用正则表达式进行验证,以便用户输入的字符不能超过4个(包括以点开头)。