Results 1 to 4 of 4

Thread: fso+file attribute

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Posts
    237

    Angry fso+file attribute

    Dear All,

    I want to know how can I check whether a file is hidden or not.
    e.g. I give file name to code and it should tell whether the file is hidden or not.

    I think this can be done by using fso but don't know how.

    Please help and guide.

    Thanks.
    software engineer

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: fso+file attribute

    Here is the code:
    VB Code:
    1. ' This routine also works with open files
    2. ' and raises an error if the file doesn't exist.
    3. Function GetAttrDescr(filename As String) As String
    4.     Dim result As String, attr As Long
    5.     attr = GetAttr(filename)
    6.     ' GetAttr also works with directories.
    7.     If attr And vbDirectory Then result = result & " Directory"
    8.     If attr And vbReadOnly Then result = result & " ReadOnly"
    9.     If attr And vbHidden Then result = result & " Hidden"
    10.     If attr And vbSystem Then result = result & " System"
    11.     If attr And vbArchive Then result = result & " Archive"
    12.     ' Discard the first (extra) space.
    13.     GetAttrDescr = Mid$(result, 2)
    14. End Function
    CS

  3. #3
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: fso+file attribute

    Do you need any more help on this thread?
    CS

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: fso+file attribute

    You can use Dir or GetAttr:
    VB Code:
    1. Private Function CheckAttr(ByVal sPath As String, Optional ByVal vbAttr As VbFileAttribute = vbNormal) As Boolean
    2.     ' Using Dir:
    3.     CheckAttr = Len(Dir(sPath, vbAttr))
    4.     ' or
    5.     ' using GetAttr
    6.     CheckAttr = GetAttr(sPath) And vbAttr
    7. End Function
    bear in mind that the GetAttr method will error if the file doesn't exist

Posting Permissions

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



Click Here to Expand Forum to Full Width