Link to home
Start Free TrialLog in
Avatar of zachvaldez
zachvaldezFlag for United States of America

asked on

exclude hidden files

I have this code in a loop.. but id like to exclude the hidden .doc files. Can someone imprve it?
 'add the doc files
                                For Each CurrentFileInfo As FileInfo In DirInfo.GetFiles()


                                    If CurrentFileInfo.Extension = ".doc" Then
                                        zip.AddFile(CurrentFileInfo.FullName)
                                    End If

                                Next


this code includes the hidden files with start of "~"
Avatar of Paulo Pimenta
Paulo Pimenta
Flag of Portugal image

On the FileInfo class there's the Attributes property. Through it, yo may know if a certain file is hidden or not, among other things.
Hope it helps.
Cheers,
eLN
Hence, you would have somethong like this:
 
For Each CurrentFileInfo As FileInfo In DirInfo.GetFiles()
    If CurrentFileInfo.Extension = ".doc" And CurrentFileInfo.Attributes <> FileAttributes.Hidden Then
        zip.AddFile(CurrentFileInfo.FullName)
    End If
Next

Open in new window

Avatar of Todd Gerbert
You need to change line 2 in above example to:

If CurrentFileInfo.Extension = ".doc" And Not CurrentFileInfo.Attributes.HasAttribute(FileAttributes.Hidden) Then


Avatar of zachvaldez

ASKER

to use hasattribute a namespace should be added. which one?
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
perfect!. I already got the system.io namespace. this work now