Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default FileSearch - help


"Tom Ogilvy" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default FileSearch - help


"Tim Williams" <timjwilliams at gmail dot com wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileSearch in a combo box michaelberrier Excel Discussion (Misc queries) 0 June 16th 06 12:21 AM
Filesearch in VB6 Colin Charman Excel Programming 3 June 18th 04 04:18 PM
FileSearch Stephen[_6_] Excel Programming 8 June 12th 04 11:14 PM
FileSearch using VBA Mark[_31_] Excel Programming 2 December 24th 03 05:49 PM
.FileSearch Randall[_3_] Excel Programming 4 November 26th 03 01:48 AM


All times are GMT +1. The time now is 03:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"