Zum Hauptinhalt gehen

Suche

Suche

Finding File With Wildcard

Kommentare

2 Kommentare

  • Avatar
    Legacy Poster
    Thought I'd answer my own post...

    Managed to find a way to use only the employee number when searching for a photo, like so:

    [code]Dim fso, f, f1, fc, fq

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder("G:\gsgem\EmployeePhoto")
    Set fc = f.Files
    fq = 0

    For Each f1 in fc
    EmployeeNrVar = Mid(f1.name, 1, 4)
    If EmployeeNrVar = EmployeeNr Then
    FileName = f1.name
    fq = 1
    End If
    If fq = 1 Then
    Exit For
    End If
    Next

    Value = FileName[/code]

    Works quite nice... [s]But, it's slooooooooow! Since I have so many photos to look through it takes about 1-2 minutes to find each photo.

    If anyone has a better way, please let me know.[/s]

    Edit: Added an "Exit For" to make the search a little faster. When the right photo is found, exit the search...
    0
  • Avatar
    Fernando Ramos Miracle
    Hello Johan,

    Many thanks for providing your own answer for your post. As the "Files Collection" is probably the way to go with this issue as you've already illustrated I just wanted to add a general example for a function using the For Each... statement:

    [i]Function ShowFolderList(folderspec)
    Dim fso, f, f1, fc, s
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(folderspec)
    Set fc = f.Files
    For Each f1 in fc
    s = s & f1.name
    s = s & "<BR>"
    Next
    ShowFolderList = s
    End Function[/i]

    Regards.
    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.