tags:

views:

21

answers:

2

i need to write a vba script that will find a file. the file could be in three different locations

how do i find where the file is?

the file must have a specific string as part of the file name

my file name could be 9424.bas or 9424a.esy or 9424_.bas or 9424...esy, i dotn know what the file name exactly is but i know the important characters 9424

+1  A: 
If Dir("file_location_1") <> "" Then
  ''# File is in 1
ElseIf Dir("file_location_2") <> "" Then
  ''# File is in 2
ElseIf Dir("file_location_3") <> "" Then
  ''# File is in 3
Else
  ''# File is not found
End If

For more than three possible locations an Array and a For loop would be the nicer solution.

Tomalak
my file name could be 9424.bas or 9424a.esy or 9424_.bas or 9424...esy, i dotn know what the file name exactly is but i know the important characters 9424
I__
+1  A: 
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists("folder1" + "filename") then
    ' folder1
ElseIf fso.FileExists("folder2" + "filename") then
    ' folder2
ElseIf fso.FileExists("folder3" + "filename") then
    ' folder3
End If
volody