Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filename With Variable (XP; SP3)

    I know how to determine if a file exists but Is it possible to determine if it exists with a variable?

    Example:
    in :C:Hold" there is a file named JS_MINE_1234.csv where the text "1234" changes. I thought perhaps is was possible to determine if file "JS_MINE*.csv" existed.

    Sub TestIt()
    Dim Results As String
    TheFile = "C:HoldJS_MINE*.csv"
    Results = Dir$(TheFile)
    If Results = "" Then
    MsgBox "File Doesn't Exist!"
    Else
    MsgBox "Found It"
    End If
    End Sub


    Thanks,
    John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filename With Variable (XP; SP3)

    Have you tested the code? If so, what was the result?

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename With Variable (XP; SP3)

    Hans,

    The result of my testing proved that the file did not exist. The variable "TheFile" = "C:HoldJS_MINE*.csv" is passed and of course it does not recognize the asterisk (wildcard) whereby the file it should be finding is "C:HoldJS_MINE_1234.csv".

    I'm not sure if it is even possible to pass a wildcard.

    Regards,
    John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filename With Variable (XP; SP3)

    Check the spelling VERY carefully. The Dir function does handle wildcards.
    I copied your function into a module and replaced C:HoldJS_MINE*.csv with a pattern that exists on my PC (including an asterisk). It worked as intended.

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename With Variable (XP; SP3)

    Hans,

    Got the concept but not the spelling.

    Thanks, <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    John

Posting Permissions

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