How Find All files within a folder and sub folder with multi extension

roykana

Active Member
Joined
Mar 8, 2018
Messages
311
Office Version
  1. 2010
Platform
  1. Windows
Dear ALL,

the code below is appropriate but can only be one extension and I want with multi extension by only modifying a little in the code below.


Thanks




VBA Code:
Sub Find_Files_Path()
    Dim fldr As FileDialog
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
    fldr.Show
    f = fldr.SelectedItems(1)
    f = f & "\"
    ibox = InputBox("File Must Contain (Note * wildcards can be used)", , "*.jpg*")
    On Error GoTo ext
    sn = Split(CreateObject("wscript.shell").exec("cmd /c Dir """ & f & ibox & """ /s /a /b").stdout.readall, vbCrLf)
    Sheets(1).Cells(1).Resize(UBound(sn) + 1) = Application.Transpose(sn)
ext:
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi roykana,

Try this:

VBA Code:
Option Explicit
Sub Find_Files_Path()
    Dim fldr As FileDialog, f As String, ibox As String, sn() As String
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
    fldr.Show
    f = fldr.SelectedItems(1)
    f = f & "\"
    'ibox = InputBox("File Must Contain (Note * wildcards can be used)", , "*.jpg*")
    On Error GoTo ext
    'sn = Split(CreateObject("wscript.shell").exec("cmd /c Dir """ & f & ibox & """ /s /a /b").stdout.readall, vbCrLf)
    sn = Split(CreateObject("wscript.shell").exec("cmd /c Dir """ & f & "*" & """ /s /a /b").stdout.readall, vbCrLf)
    Sheets(1).Cells(1).Resize(UBound(sn) + 1) = Application.Transpose(sn)
ext:
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top