Hello everyone!

Is there a way in VBA to find a file name that has an unknown portion to it? Let me explain:

Our computer system is UNIX based. It is creating a text file for us that uses the date, the hour, minutes and seconds that the file was created as its file name. This file name looks exactly like this:

20141210.104056

Finding the date isn't an issue. The unknown part is the date and time the file was created as the "file extension" (.104056) is the time stamp. That is the variable that I need to access.

Is there an "any extension" code such as "filePath = 20141210.(asterisk)" (or some other character) that would allow me to open this file?

In advance, thanks for your assistance.

Don

Well, you need the full path to the folder but then yes, this should work like:
" 20141210.* " which is working on windows. For unix have a look at this:
http://www.acnenomor.com/1652273p1/how-to-get-the-file-name-from-the-path
O.K having written this the problem may be with length of the file extension, in windows it is only three characters.You might need to write a small conversion program to get somethig like:
20141210_104056.txt which then can be read by windows. Just a thought.

I may not be as clear as I should be: The code I'm writing is in VBA. I'm actually writting this behind some EXCEL documents. So the actual code you're suggesting I try would look like this?:

fileName = Year(Today()) & Month(Today()) & Day(Today())
filePath = "O:\IPSDATA\PMS03361A\" & fileName & ".*"

Is this correct?

Again, thanks for reaching out.

Make a search for sample VBA code that calls the API function FindFirstFile. Click Here

O.K. we need to be clear about file naming in unix. Unix files don't have an extension. You can have something like: 123456.pdf to indicate a pdf file but the .pdf is not an extension like in windows but the filename. Under DOS you had the restrictions of Filename max. 8 characters and a three character extension like: 12345678.txt.
Under windows a file name, including path can now have 260 characters. So to get back to your problem:
The filename you are working with is: 20141210.104056
So a

  filePath = "O:\IPSDATA\PMS03361A\" & 20141210.104056 & ".*"

will not work since you want to search characters in the filename. So to use wild cards it has to be somethig like:
20141210.###### as this is the wild card for numbers. See also:
http://www.databison.com/string-comparison-function-in-vba/
http://answers.google.com/answers/threadview/id/191785.html

Minimalist, I've done some testing. The wildcards work perfectly! Thank you!!

Glad that it worked. Please mark the thread as solved. Thankyou.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.