Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

exclude hidden files

Posted on 2011-02-14
6
Medium Priority
?
781 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

963 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