ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sime function to find files (https://www.excelbanter.com/excel-programming/345785-sime-function-find-files.html)

Ivica Lopar

Sime function to find files
 
I need to find all files in some directories and all thtis files start with
the same string.

Regards
Lopar



Rowan Drummond[_3_]

Sime function to find files
 
What do you want to do with the files once found? Open them, list their
names on a sheet, ....

Regards
Rowan

Ivica Lopar wrote:
I need to find all files in some directories and all thtis files start with
the same string.

Regards
Lopar



Ivica Lopar

Sime function to find files
 

I wont to put string in textbox1 and then clik commandbutton
and have all path of files in listbox1
lop

*** Sent via Developersdex http://www.developersdex.com ***

Rowan Drummond[_3_]

Sime function to find files
 
I'm guessing here but if you want to enter the path in TextBox1 and have
all excel files in that folder listed in listbox1 then you would do it
like this:

Private Sub CommandButton1_Click()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFolder = objFSO.GetFolder(Me.TextBox1.Text)
On Error GoTo 0
If Not objFolder Is Nothing Then
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Me.ListBox1.AddItem objFile.Name
End If
Next
End If
End Sub

Hope this helps
Rowan

ivica lopar wrote:
I wont to put string in textbox1 and then clik commandbutton
and have all path of files in listbox1
lop

*** Sent via Developersdex http://www.developersdex.com ***


Ivica Lopar

Sime function to find files
 
This is what I wont but this files are pictures not excel files


Regards
lop

*** Sent via Developersdex http://www.developersdex.com ***

Ivica Lopar

Sime function to find files
 
Private Sub CommandButton7_Click()


Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFolder = objFSO.GetFolder(Me.TextBox4.Text)
On Error GoTo 0
If Not objFolder Is Nothing Then
For Each objFile In objFolder.Files
If objFile.Type = "JPEG Image" Then
Me.list1.AddItem objFile.Name
End If
Next
End If

This is what I tryed but it did not work out




lop

*** Sent via Developersdex http://www.developersdex.com ***

Ivica Lopar

Sime function to find files
 
I heve folder named "Pictures" in that folder I have pictures that there
names start with some string for example "1201052"
now when i put this string in TextBox1 I wont all path of pictures that
start with that string to put in listBox1


Regards
lop

*** Sent via Developersdex http://www.developersdex.com ***

Rowan Drummond[_3_]

Sime function to find files
 
Try it like this entering the path for your pictures folder in textbox4
and the string that file names start with in textbox1. Check the name of
the listbox.

Private Sub CommandButton7_Click()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFolder = objFSO.GetFolder(Me.TextBox4.Text)
On Error GoTo 0
If Not objFolder Is Nothing Then
For Each objFile In objFolder.Files
If objFile.Type = "JPEG Image" And _
objFile.Name Like Me.TextBox1.Text & "*" Then
Me.ListBox1.AddItem objFile.Name
End If

Next
End If

End Sub

Regards
Rowan

ivica lopar wrote:
Private Sub CommandButton7_Click()


Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFolder = objFSO.GetFolder(Me.TextBox4.Text)
On Error GoTo 0
If Not objFolder Is Nothing Then
For Each objFile In objFolder.Files
If objFile.Type = "JPEG Image" Then
Me.list1.AddItem objFile.Name
End If
Next
End If

This is what I tryed but it did not work out




lop

*** Sent via Developersdex http://www.developersdex.com ***


Ivica Lopar

Sime function to find files
 
Works perfect.All I need more to have path from TextBox4 in ListBox1 for
excample:

D:\My Pictures\210345_65.jpeg
D:\My Pictures\210346_65.jpeg






regards
lop

*** Sent via Developersdex http://www.developersdex.com ***

Rowan Drummond[_3_]

Sime function to find files
 
Maybe:

Private Sub CommandButton7_Click()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFolder = objFSO.GetFolder(Me.TextBox4.Text)
On Error GoTo 0
If Not objFolder Is Nothing Then
For Each objFile In objFolder.Files
If objFile.Type = "JPEG Image" And _
objFile.Name Like Me.TextBox1.Text & "*" Then
Me.ListBox1.AddItem Me.TextBox4.Text & objFile.Name
'or
' Me.ListBox1.AddItem Me.TextBox4.Text & " \" & objFile.Name
End If

Next
End If

End Sub

Regards
Rowan

ivica lopar wrote:
Works perfect.All I need more to have path from TextBox4 in ListBox1 for
excample:

D:\My Pictures\210345_65.jpeg
D:\My Pictures\210346_65.jpeg






regards
lop

*** Sent via Developersdex http://www.developersdex.com ***


Ivica Lopar

Sime function to find files
 

I find solution by my self.
I hope You will help me sometimes.
Jop You do is fantasy.
Thanks for help
If you

Regards
lop

*** Sent via Developersdex http://www.developersdex.com ***

Rowan Drummond[_3_]

Sime function to find files
 
Happy to help
Rowan

ivica lopar wrote:
I find solution by my self.
I hope You will help me sometimes.
Jop You do is fantasy.
Thanks for help
If you

Regards
lop

*** Sent via Developersdex http://www.developersdex.com ***



All times are GMT +1. The time now is 06:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com