When using the Like operator anything between square brackets is treated as a character list to match a single character.
For example if you wanted to check for A-Z you would use [A-Z].
Try this for finding [ followed by ].
Sub File_Attributes()
Dim sFolder As FileDialog
Set sFolder = Application.FileDialog(msoFileDialogFolderPicker)
If sFolder.Show = -1 Then
File_Attributes_List_Files sFolder.SelectedItems(1), True
End If
End Sub
Sub File_Attributes_List_Files(ByVal SourceFolderName As String, ByVal IncludeSubfolders As Boolean)
Dim FSO As Object
Dim SourceFolder As Object
Dim SubFolder As Object
Dim FileItem As Object
Dim r As Long
Dim pos1 As Long
Dim pos2 As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder(SourceFolderName)
r = ActiveCell.Row
For Each FileItem In SourceFolder.Files
pos1 = InStr(FileItem.Name, "[")
If pos1 > 0 Then
pos2 = InStr(FileItem.Name, "]")
If pos2 > pos1 Then
Rows(r).Insert
Cells(r, 3).Formula = FileItem.Name
r = r + 1
End If
End If
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
File_Attributes_List_Files SubFolder.Path, True
Next SubFolder
End If
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = True
End Sub
Bookmarks