Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    File or Folder? (VB 6 or VBA 8)

    If I have a string varable, is there a slick way to determine whether it is a folder or a file? "Slick" is defined as not using On Error!

    If it is a file, then I am using the FileSystemObject GetParentFolder method to return the parent folder, otherwise I return the original string. TIA --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

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

    Re: File or Folder? (VB 6 or VBA 8)

    I fear this is naive. Can't you use the FileExists and/or FolderExists methods of the FileSystemObject?

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: File or Folder? (VB 6 or VBA 8)

    It's not naive: it's genius! <img src=/S/salute.gif border=0 alt=salute width=15 height=20> It's also what I came up with. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> It just takes me a while to figure out what FileSystemObject method to use. Is there a good reference for the FileSystemObject? I've got XL97 now, so I can't even get any help files. Thanks! --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: File or Folder? (VB 6 or VBA 8)

    Edited to correct the Post No. - Sorry about that. A.C.

    Sammy, have a look at <post#=152045 >post 152045 </post#> where an API call might help.

    Andrew C

  5. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: File or Folder? (VB 6 or VBA 8)

    Thanks, Andrew! I was already using a bunch of API calls, so your solution works out better. The set of API functions in shlwapi is very nice: I also used PathRemoveFileSpec. Here is the code at the top and the bottom:
    <pre>Option Explicit
    '
    Private Declare Function PathIsDirectory Lib "shlwapi.dll" _
    Alias "PathIsDirectoryA" (ByVal pszPath As String) As Long
    '
    Private Declare Function PathRemoveFileSpec Lib "shlwapi" _
    Alias "PathRemoveFileSpecA" (ByVal pPath As String) As Long
    '
    ' Code just before returning s
    Dim s As String
    '
    If Not (CBool(PathIsDirectory(s))) Then
    Call PathRemoveFileSpec(s)
    End If</pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

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

    Re: File or Folder? (VB 6 or VBA 8)

    Sam,

    I usually start VB6 if I want to get help on subjects like this. In Office 97, there is still the Object Browser (F2 in the VBE); if you look up FileSystemObject, you get an overview of properties and methods.

    Regards,
    Hans

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: File or Folder? (VB 6 or VBA 8)

    Documentation is available online at MS: FileSystemObject Basics and Scripting Run-Time Reference.

Posting Permissions

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