Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Oct 2008
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Extension (2002/SP3)

    I'm trying to extract file names with the extension "*.out" using the following code:

    strFolder = "H:test"
    strFile = Dir(strFolder & "*.out")
    Debug.Print strFolder & strFile
    If strFile = "" Then
    MsgBox "no files found"
    Exit Sub
    End If

    All works fine, except that this code also picks up files with extensions such as "*.out1" and "*.out_".

    How can I change the code to avoid this from happening?

  2. #2
    3 Star Lounger
    Join Date
    Nov 2002
    Location
    New York, New York, USA
    Posts
    266
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Re: File Extension (2002/SP3)

    Would the following perhaps work

    strFile=Dir(strFolder&"*.ou?")

    Tom Duthie

  3. #3
    2 Star Lounger
    Join Date
    Oct 2008
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Extension (2002/SP3)

    Nope. Still the same problem.

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: File Extension (2002/SP3)

    When you are looping through the "dir code" to look at each file name do something like:

    If right(strFile,4) = ".out"
    'Process file
    'Code to work with "*.out" files
    End If

    So that only the ones with out extension get processed

    Steve

  5. #5
    2 Star Lounger
    Join Date
    Oct 2008
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Extension (2002/SP3)

    Thanks Steve, I used your suggestion and changed the code accordingly.

    Any idea why "Dir" searches for all variations of *.out* extension, rather than what was specified, ie, *.out?

  6. #6
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: File Extension (2002/SP3)

    I don't know the specifics but it may be simply that it was designed for 3 char extensions...

    Steve

Posting Permissions

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