Link to home
Create AccountLog in
Avatar of Rebecca Shabad
Rebecca Shabad

asked on

how do i open a file if i only know part of the file name

How to visible a filename*esy pattern related all files simultaneously from the directory. Please find the below code and suggest.

Const SOME_PATH As String = "C:\Anderson\"
Dim file As String
file = Dir(SOME_PATH & "filename*esy" & ".")

If (Len(file) > 0) Then
  MsgBox ("Found")
  Else
  MsgBox ("Not Found")
End If
End Sub

Open in new window

SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Rebecca Shabad
Rebecca Shabad

ASKER

Need to visible multiple files at the same time but it has been partial naming structure (eq. filename*sy).

Multiple Files in Directory:

filename1292_endeesy
filename129_endeesy
filename_Aasdeesy
filename-sasks_endeesy
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
It's possible to visible all partial named(filenames*esy) xml files via notepad?
Why not just do this at a DOS command prompt?

Open the Command Prompt, switch to the folder to report on via the CD command, and then run:

dir /b "filenames*esy.xml"

If you want to save the list of files to a file add:

dir /b "filenames*esy.xml">list.txt

then if you want open the list.txt file in Notepad for viewing.


»bp
Yes I know that method through Command Prompt method. So it's not possible to code in word vba?
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
The above code is not working its only showing No files found and print C:\log: in word
The two constants need to be set properly to specify a location where matching files actually exist.  There must be a backslash at the end of the BASE_FOLDER constant.

   Const BASE_FOLDER As String = "C:\Anderson\"
    Const FILE_FILTER As String = "filename*esy.xml"



»bp