Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding files

Status
Not open for further replies.

Ricjd

Programmer
Sep 12, 2002
104
GB
I need a simple solution to find certian files.

I need to find all the files with the word "test" in the file name.

It needs to look in the folder "d:/test/" and all it's sub folders.

Once the files are founds I need the location and file name displayed in a list.

If anyone could help me, would be extremely grateful.

Thanking you in advance

Rick
 
Well couple of approachs are available.
1. Use DIR() to loop through. Below is example to fill list/combobox.
Private Sub cmd_InputDir_Click()
Dim lcFiles As String
Me.txtInputDir = FolderBrowse.GetFolderName()
Me.txtInputDir.Requery
lcFiles = GetInputFileNames(Me.txtInputDir.Value)
Me.lst_Files.RowSource = lcFiles
Me.lst_Files.Requery
End Sub

Public Function GetInputFileNames(lcInPath)
Dim lcTempStr As String
Dim lvTempVar As Variant

lcTempStr = ""
lcInPath = lcInPath & "*.mdb"

' Returns filename with specified extension. If more than one *.ini
' file exists, the first file found is returned.
lvTempVar = Dir(lcInPath)
Do While lvTempVar <> &quot;&quot; ' Start the loop.
' Call Dir again without arguments to return the next *.dat file in the same directory.
If lcTempStr = &quot;&quot; Then
'1st item
lcTempStr = lvTempVar
Else
lcTempStr = lcTempStr & &quot;;&quot; & lvTempVar
End If
lvTempVar = Dir
Loop
If lcTempStr = &quot;&quot; Then
GetInputFileNames = &quot;No DAT Files&quot;
Me.lst_Files.Enabled = False
Else
GetInputFileNames = lcTempStr
Me.lst_Files.Enabled = True
End If

End Function

2. Use FileScripting Object. Sorry no good code examples. Most likely most efficient from code perspecitive. I would recommend using this over DIR() or DOS Bat file.

3. Create a DOS Batch file that executes a DIR command and sends results to a text file. Read the text file into a database table. Sorry can't find example... from what I recall, used Shell command to execute DOS Bat file. Then needed to add a few seconds delay to permit file to complete. Then read text file into database table.

htwh,


Steve Medvid
&quot;IT Consultant & Web Master&quot;

Chester County, PA Residents
Please Show Your Support...
 
Thanx Steve

I have gone with the FileScripting object.

Cheers again

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top