+ Reply to Thread
Results 1 to 5 of 5

FileSearch - help

  1. #1
    -Zoki-
    Guest

    FileSearch - help

    Hello to all

    I have one problem which is probably peace of cake for you.
    I have code below which in "list1" display list of all files from
    path "TextBox4" and which begin with "TextBox3".

    Let say that TextBox4 value is c:\test\ and TextBox5 value is 123456789.

    When program run, in "List1" I get displayed file paths, for instance :
    c:\test\123456789_1.jpg
    c:\test\123456789_2.jpg
    c:\test\123456789_3.jpg
    c:\test\123456789_4.jpg

    Problem is that I don't want whole path, I want only file names.
    123456789_1.jpg
    123456789_2.jpg
    123456789_3.jpg
    123456789_4.jpg

    I guess that problem is stupid but I can't find solution.

    Thanks in advance !


    Code
    ----------------------------------------------------------------------------
    -------------
    Private Sub CommandButton7_Click()

    Dim Path As String
    Dim fsoFileSearch As FileSearch
    Dim varFile As Variant

    list1.Clear
    List2.Clear

    Path = (Me.TextBox4.Text)


    Set fsoFileSearch = Application.FileSearch
    On Error Resume Next
    With fsoFileSearch
    .NewSearch
    .LookIn = "Path"
    .Filename = (Me.TextBox4.Text) & "*" & ".jpg"
    .SearchSubFolders = False

    If .Execute(msoSortByFileName, msoSortOrderAscending, True) > 0 Then
    For Each varFile In .FoundFiles

    Me.list1.AddItem varFile


    Next varFile
    End If
    End With

    End Sub
    ----------------------------------------------------------------------------
    ---------------------------



  2. #2
    Tom Ogilvy
    Guest

    RE: FileSearch - help

    Private Sub CommandButton7_Click()

    Dim Path As String
    Dim fsoFileSearch As FileSearch
    Dim varFile As Variant
    Dim v as Variant

    list1.Clear
    List2.Clear

    Path = (Me.TextBox4.Text)


    Set fsoFileSearch = Application.FileSearch
    On Error Resume Next
    With fsoFileSearch
    .NewSearch
    .LookIn = "Path"
    .Filename = (Me.TextBox4.Text) & "*" & ".jpg"
    .SearchSubFolders = False

    If .Execute(msoSortByFileName, msoSortOrderAscending, True) > 0 Then
    For Each varFile In .FoundFiles
    v = split(varfile,"\")
    Me.list1.AddItem v(ubound(v))
    Next varFile
    End If
    End With

    End Sub


    --
    Regards,
    Tom Ogilvy



    "-Zoki-" wrote:

    > Hello to all
    >
    > I have one problem which is probably peace of cake for you.
    > I have code below which in "list1" display list of all files from
    > path "TextBox4" and which begin with "TextBox3".
    >
    > Let say that TextBox4 value is c:\test\ and TextBox5 value is 123456789.
    >
    > When program run, in "List1" I get displayed file paths, for instance :
    > c:\test\123456789_1.jpg
    > c:\test\123456789_2.jpg
    > c:\test\123456789_3.jpg
    > c:\test\123456789_4.jpg
    >
    > Problem is that I don't want whole path, I want only file names.
    > 123456789_1.jpg
    > 123456789_2.jpg
    > 123456789_3.jpg
    > 123456789_4.jpg
    >
    > I guess that problem is stupid but I can't find solution.
    >
    > Thanks in advance !
    >
    >
    > Code
    > ----------------------------------------------------------------------------
    > -------------
    > Private Sub CommandButton7_Click()
    >
    > Dim Path As String
    > Dim fsoFileSearch As FileSearch
    > Dim varFile As Variant
    >
    > list1.Clear
    > List2.Clear
    >
    > Path = (Me.TextBox4.Text)
    >
    >
    > Set fsoFileSearch = Application.FileSearch
    > On Error Resume Next
    > With fsoFileSearch
    > .NewSearch
    > .LookIn = "Path"
    > .Filename = (Me.TextBox4.Text) & "*" & ".jpg"
    > .SearchSubFolders = False
    >
    > If .Execute(msoSortByFileName, msoSortOrderAscending, True) > 0 Then
    > For Each varFile In .FoundFiles
    >
    > Me.list1.AddItem varFile
    >
    >
    > Next varFile
    > End If
    > End With
    >
    > End Sub
    > ----------------------------------------------------------------------------
    > ---------------------------
    >
    >
    >


  3. #3
    -Zoki-
    Guest

    Re: FileSearch - help


    "Tom Ogilvy" <[email protected]> wrote in message
    news:[email protected]...
    > Private Sub CommandButton7_Click()
    >
    > Dim Path As String
    > Dim fsoFileSearch As FileSearch
    > Dim varFile As Variant
    > Dim v as Variant
    >
    > list1.Clear
    > List2.Clear
    >
    > Path = (Me.TextBox4.Text)
    >
    >
    > Set fsoFileSearch = Application.FileSearch
    > On Error Resume Next
    > With fsoFileSearch
    > .NewSearch
    > .LookIn = "Path"
    > .Filename = (Me.TextBox4.Text) & "*" & ".jpg"
    > .SearchSubFolders = False
    >
    > If .Execute(msoSortByFileName, msoSortOrderAscending, True) > 0

    Then
    > For Each varFile In .FoundFiles
    > v = split(varfile,"\")
    > Me.list1.AddItem v(ubound(v))
    > Next varFile
    > End If
    > End With
    >
    > End Sub
    >
    >
    > --
    > Regards,
    > Tom Ogilvy
    >



    Thank you for very fast response, it is working fine.
    Now I noticed another problem with sorting.
    This problem was present also before.

    In command below:
    ----------------------------------------------------------------------------
    ------------------
    If .Execute(msoSortByFileName, msoSortOrderAscending, True) > 0 Then
    ----------------------------------------------------------------------------
    -----------------------

    I should receive file names sorted by name, but this is not working good.
    For instance , this files below are sorted in this way:

    123456789_1_13.jpg
    123456789_1_3397.jpg
    123456789_1_3463.jpg
    123456789_1_827.jpg
    123456789_10_1626.jpg
    123456789_10_2550.jpg
    123456789_2_2705.jpg
    123456789_2_556.jpg

    And it should be sorted in this way (this si how it looks in win explorer):
    123456789_1_13.jpg
    123456789_1_827.jpg
    123456789_1_3397.jpg
    123456789_1_3463.jpg
    123456789_2_556.jpg
    123456789_2_2705.jpg
    123456789_10_1626.jpg
    123456789_10_2550.jpg

    It looks like that this subroutine don't understand numbers in file names,
    numbers
    are represent as text and sorting is performed according that.

    In this example my files are named only with numbers, but there are
    situations
    when they have some letter characters for instance N123456789_24_15.jpg
    I there a possibility to solve this problem?

    Best Regards!!




  4. #4
    Tim Williams
    Guest

    Re: FileSearch - help

    When sorting, the filenames are treated as text, so your sort order is what would be expected.
    Only solution is to either pad your numbers with 0's (eg. use "_002_" and not "_2_") or to separate the nubers and text and sort by
    the two fields (the numbers being sorted as numeric).

    I suspect the view you have from Windows Explorer may be sorted by date and not by filename, so maybe you could consider applying
    the same sort in Excel.

    --
    Tim Williams
    Palo Alto, CA



    >
    > Thank you for very fast response, it is working fine.
    > Now I noticed another problem with sorting.
    > This problem was present also before.
    >
    > In command below:
    > ----------------------------------------------------------------------------
    > ------------------
    > If .Execute(msoSortByFileName, msoSortOrderAscending, True) > 0 Then
    > ----------------------------------------------------------------------------
    > -----------------------
    >
    > I should receive file names sorted by name, but this is not working good.
    > For instance , this files below are sorted in this way:
    >
    > 123456789_1_13.jpg
    > 123456789_1_3397.jpg
    > 123456789_1_3463.jpg
    > 123456789_1_827.jpg
    > 123456789_10_1626.jpg
    > 123456789_10_2550.jpg
    > 123456789_2_2705.jpg
    > 123456789_2_556.jpg
    >
    > And it should be sorted in this way (this si how it looks in win explorer):
    > 123456789_1_13.jpg
    > 123456789_1_827.jpg
    > 123456789_1_3397.jpg
    > 123456789_1_3463.jpg
    > 123456789_2_556.jpg
    > 123456789_2_2705.jpg
    > 123456789_10_1626.jpg
    > 123456789_10_2550.jpg
    >
    > It looks like that this subroutine don't understand numbers in file names,
    > numbers
    > are represent as text and sorting is performed according that.
    >
    > In this example my files are named only with numbers, but there are
    > situations
    > when they have some letter characters for instance N123456789_24_15.jpg
    > I there a possibility to solve this problem?
    >
    > Best Regards!!
    >
    >
    >




  5. #5
    -Zoki-
    Guest

    Re: FileSearch - help


    "Tim Williams" <timjwilliams at gmail dot com> wrote in message
    news:O7k%23ja%[email protected]...
    > When sorting, the filenames are treated as text, so your sort order is

    what would be expected.
    > Only solution is to either pad your numbers with 0's (eg. use "_002_" and

    not "_2_") or to separate the nubers and text and sort by
    > the two fields (the numbers being sorted as numeric).
    >
    > I suspect the view you have from Windows Explorer may be sorted by date

    and not by filename, so maybe you could consider applying
    > the same sort in Excel.
    >
    > --


    Hi , in Explorer files are sorted by file name and it sorted OK.
    But never mind, I have bigger problem now, this complete code do not run on
    my
    computer on Job and several others computers, on my home computer
    run perfectly *?$#&
    I don't know what is happening but it looks like that this FileSearch can't
    find any file.
    I seen on google that lot of peoples have trouble with this FileSearch
    function.


    Zok






+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1