I need to write an if function that finds if the a specific file exists, but the directory of the file contains unknown elements that may change from occasion to occasion. The code I have so far is:
If Dir(ProjectsFolder & ComboBox_ProjectType.Text & "\" & ProjectNumber & "\" & ProjectNumber & "_Rokasgramata\", ProjectNumber & "*User Manual*.pdf")(0) = "" Then
It returns an error and it's probably because of "*" What am I doing wrong? Could someone, please, help me with this one?
CodePudding user response:
When working with paths use IO.Path.Combine
Use that path to create a New IO.DirectoryInfo(path)
This object has .Exists
property to ensure that the directory exists.
Finally use .EnumerateFiles(ProjectNumber & "*User Manual*.pdf").Any()
To check if any such file exists.
CodePudding user response:
I was very close and figured it out on my own
If Dir(ProjectsFolder & ComboBox_ProjectType.Text & "\" & ProjectNumber & "\" & ProjectNumber & "_Rokasgramata\" & ProjectNumber & "*User Manual*.pdf") = "" Then