Wildcards not working with SetAttr

A

Andrew

Hi,

I'm trying to find and delete all hidden files in a directory.

The hidden files are resource forks generated by Mac users on our
Network and all contain the filename format "._(filename).xls"

Since the Kill command won't work on Hidden files I have been playing
with the SetAttr and Kill commands in combination with wildcards to
find and delete instances of these files.
Assuming a hidden file is called ._Name.xls I figured that by
substituting a "*" for "Name" that would take care of things, but keep
getting the error message "Bad Filename or number".


Here is my code:

SetAttr "Path\._*.xls", 0
Kill "Path\._*.xls"

Where am I going wrong?
Is there a better way to do this?

Cheers

Andrew
 
R

Ron Weiner

SetAttr can not accept wildcards as part of its Pathname property. You will
need to use the Dir() command in a loop to get the filename of each file
that meets your criteria and then ste the attrribute and delete it. Here is
a untested function that should do what you want.

Sub DeleteHidden(strFilespec)
Dim strFilename As String, strPath As String

strPath = Left(strFilespec, InStrRev(strFilespec, "\"))
strFilename = Dir(strFilespec, vbHidden)
Do While Len(strFilename) > 0
If (GetAttr(strPath & strFilename) And vbHidden) <> 0 Then
SetAttr strPath & strFilename, vbNormal
Kill strPath & strFilename
End If
strFilename = Dir()
Loop
End Sub

This will delete only the files that meet your filespec criteria AND whose
hidden attribute is set.

You can use it thusly

DeleteHidden "C:\Full\Pathname\Filespec*.xls"

Ron W
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top