ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   File Search (https://www.excelbanter.com/excel-programming/306340-file-search.html)

unplugs[_48_]

File Search
 
GOod day all..

How to do file search?

I had reading some codes in this forum.. But none suit m
application..

I want to search a file(file name is dummy for first time created
whether it exists or not, if not exists, it will create the dummy.txt
if this file name(dummy.txt) exists, it will automatically assig
another name to it, for example, Engine001, and it will search agai
and check whether this file name(Engine001) exist or not. If exist, i
will create another file name, Engine002 .... until the file name i
not exists in the folder, it will use the file name and move on t
store data in the file.

How to do the search for the above application?

Helps from anyone is appreciated~
:

--
Message posted from http://www.ExcelForum.com


unplugs[_49_]

File Search
 
Function FileExists(fname As String) As Boolean
With Application.FileSearch
.LookIn = "C:\ "
.NewSearch
.filename = fname
.Execute

If .FoundFiles.Count = 0 Then
FileExists = False
Else
FileExists = True
End If
End With
End Function



Can anyone help me to check whether the function above correct o
not..? When I debug the code above, whether the file exists or not, th
.FoundFiles.Count is alwaz equal to 0..... Why this happen

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 12:20 PM.

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