Solved

exclude hidden files

Posted on 2011-02-14
6
772 Views
Last Modified: 2012-06-27
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 "~"
0
Comment
Question by:zachvaldez
  • 2
  • 2
  • 2
6 Comments
 
LVL 17

Expert Comment

by:paulop1975
ID: 34889875
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
0
 
LVL 17

Expert Comment

by:paulop1975
ID: 34889906
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

0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 34889962
You need to change line 2 in above example to:

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


0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:zachvaldez
ID: 34890417
to use hasattribute a namespace should be added. which one?
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 250 total points
ID: 34890541
Sorry, it's HasFlag() not HasAttribute, and is only in .Net 4.  If you're at an earlier version of .Net try this:

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

Open in new window

Private Function HasFileAttribute(ByVal fileAttributes As System.IO.FileAttributes, ByVal attribute As System.IO.FileAttributes) As Boolean
    Return (fileAttributes And attribute) > 0
End Function

Open in new window

0
 

Author Comment

by:zachvaldez
ID: 34890750
perfect!. I already got the system.io namespace. this work now
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to use odbc in vb to connect to ms sql 14 63
location of a form 2 25
Convert Ctime to date time in textfile? 7 34
Access Schema 6 26
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question