Consulting

Results 1 to 5 of 5

Thread: Using wildcard in folder name

  1. #1
    VBAX Newbie
    Joined
    Mar 2011
    Posts
    3
    Location

    Using wildcard in folder name

    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:

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

    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?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to add more path details, something like

    [vba]

    filePath =Dir("C:\somedir\somesub\2011-01-14_*", vbDirectory) [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Mar 2011
    Posts
    3
    Location
    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...

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.

  5. #5
    VBAX Newbie
    Joined
    Mar 2011
    Posts
    3
    Location
    Quote Originally Posted by Kenneth Hobs
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •