Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Deleting Hidden Files (VBA/Word/2330 SP2)

    I am using VBA to clean up some old folders, but am thwarted by hidden files. I adapted the following code from the code found <!post=here,1917>here<!/post>, but the fso is unable to see the hidden files. <pre>Sub ClearAttributes(filespec)
    Dim fs, f
    Set fs = CreateObject("Scripting.FileSystemObject")
    On Error GoTo NoFile
    Set f = fs.GetFile(fs.GetFileName(filespec))
    If f.Attributes <> 0 Then
    f.Attributes = 0
    End If
    NoFile:
    On Error GoTo 0
    End Sub
    </pre>


    If anyone can advise me on how to clear all attributes from a file, irrespective of the current settings, I would be much obliged.

    T.I.A.
    Regards
    Don

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

    Re: Deleting Hidden Files (VBA/Word/2330 SP2)

    Try changing

    Set f = fs.GetFile(fs.GetFileName(filespec))

    to

    Set f = fs.GetFile(filespec)

    It works for me - whether I show hidden files in Windows Explorer or not.

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Deleting Hidden Files (VBA/Word/2330 SP2)

    Thank you for the speedy response Hans.
    On reading and implementing your response, I knew that I had messed up somewhere; because it still didn't work-- until I included the path in the filespec .
    I'll soon be known as Teflon Don (everything seems to slip my mind).
    Regards
    Don

  4. #4
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Deleting Hidden Files (VBA/Word/2330 SP2)

    Am I missing something fundamental, or is this site incorrect in its statement that the Attributes property if the File object is Read-Only?

    The code identified in my earlier post, when modified as you suggested changes the attributes quite nicely.
    Regards
    Don

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

    Re: Deleting Hidden Files (VBA/Word/2330 SP2)

    Here is the "official" reference on the Microsoft site: Attributes Property. Some attributes can be set, such as Read-Only ( <img src=/S/grin.gif border=0 alt=grin width=15 height=15>), Hidden, System, and Archive. Others can only be read, such as Directory, Volume, Alias and Compressed.

  6. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Deleting Hidden Files (VBA/Word/2330 SP2)

    Thank you Hans.
    Now it makes sense.
    Regards
    Don

Posting Permissions

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