PDA

View Full Version : Using wildcard in folder name



actuary
03-17-2011, 03:17 AM
Hello,

I’m trying to open some xml-files using VBA. The problem is that the these files are not all in the same folder. Every day a new file is created in a new directory. The filename is always the same, but the filepath is always different. I’ve got foldernames like 2011-01-14_21-45-16 and 2011-01-15_21-43-22 etc.

The date I’ll always know beforehand (one new directory every day), but the time differs fromday to day. So I want to use a wildcard in searching for the correct foldername.

I tried the following:


filePath =Dir("2011-01-14_*", vbDirectory)


but then filePath = “”. I even tried

filePath =Dir("2011-01-14_21-45-16", vbDirectory) – I know this directory exists, but it still returns a filePath = “”.

I’m probably using the Dir-statement wrong L

Can anybodyhelp me?

Bob Phillips
03-17-2011, 03:30 AM
You need to add more path details, something like



filePath =Dir("C:\somedir\somesub\2011-01-14_*", vbDirectory)

actuary
03-17-2011, 04:00 AM
Tnx,

I forgot to mention that I'm already using a ChDir command before the Dir command to change to the right directory. But even if I puth the complete path into the Dir-statement it still doesn't work...

Could this be because I'm trying to acces a network path (and not a local path)?

I now use

[vba]
filePath = Dir ("\ \ build \ bla \ bla \ bla \ 2011-01-14_*", vbDirectory)
[\vba]

without the spaces obviously, but otherwise it is recognised as a link, and I'm not able to post links or something...

Kenneth Hobs
03-17-2011, 05:41 AM
Yes. Use a virtual drive for the network path. You can add it by Explorer and tell it to create it at each boot or a DOS command called SUBST.

actuary
03-17-2011, 06:21 AM
Yes. Use a virtual drive for the network path. You can add it by Explorer and tell it to create it at each boot or a DOS command called SUBST.

That did the trick. Apparently Dir connot work with UNC.
Big thanks for all your help :bow: